What is the differences between onAttach() and isAdded() in android Fragment?

♀尐吖头ヾ 提交于 2021-02-17 07:16:09

问题


Can anyone tell me what are the different of use of onAttach() and isAdded in Android Fragment?

When create a new fragment onAttach() method creating default.

I checked this question, the question is asked about !onDetech() and isAdded() , also one answer there, but I am not clear with that.. Thanks


回答1:


This could be answered simply reading javadocs:

    /**
     * Called when a fragment is first attached to its context.
     * {@link #onCreate(Bundle)} will be called after this.
     */
    public void onAttach(Context context) 

and

    /**
     * Return true if the fragment is currently added to its activity.
     */
    final public boolean isAdded()



回答2:


onAttach() is called when a fragment is connected to an activity. Where isAdded() override method will come up with true if it is connected successfully to an activity.




回答3:


  • onAttach()

Called when a fragment is first attached to its context. onCreate(Bundle) will be called after this.

  • isAdded ()

Return true if the fragment is currently added to its activity.



来源:https://stackoverflow.com/questions/52607945/what-is-the-differences-between-onattach-and-isadded-in-android-fragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!