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

前端 未结 3 1898
闹比i
闹比i 2021-01-29 11:55

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

相关标签:
3条回答
  • 2021-01-29 12:46

    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.

    0 讨论(0)
  • 2021-01-29 12:49
    • 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.

    0 讨论(0)
  • 2021-01-29 12:56

    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()
    
    0 讨论(0)
提交回复
热议问题