does Saved instance state on onCreate and onActivityCreated of a fragment differs?

StackOverflow https://stackoverflow.com/questions/23320375

  •  10-07-2023
  •  | 
  •  

سؤال

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.savedInstanceState = savedInstance;
    }
@Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        try {
            Log.d("Equals?",savedInstanceState.equals(this.savedInstanceState));
        } catch (Exception e) {
            Log.d("Equals?",savedInstanceState==this.savedInstanceState);
        }
    }

Will this always\never or only on some cases log true?

EDIT: after seeing Henry's comment, lets address my question as if Intent has overriden its equals and it does compare those objects content, not by references...

هل كانت مفيدة؟

المحلول

onCreate(Bundle) called to do initial creation of the fragment.

onActivityCreated(Bundle) tells the fragment that its activity has completed its own Activity.onCreate().

so we can say that Bundle savedInstanceState are same at both places.

for more visit

http://developer.android.com/reference/android/app/Fragment.html

http://developer.android.com/guide/components/fragments.html

you wrote

@Override
    public void onCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        this.savedInstanceState = savedInstance;
    }

i do not understand which lifecycle mehod is onCreated i think it should be onCreate and the lines should be

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
....}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top