5

i have a listFragment this is my onActivityCreated:

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (savedInstanceState != null) {
        utenti=savedInstanceState.getParcelableArrayList("array");
    }else{
        threadutenti= (GetUtenti) new GetUtenti(this.getActivity(), utenti).execute();
    }

When i rotate my device i have first savedInstanceState non null (i got it) but after onActivityCreated is called with onActivityCreated null!! why? i want get my object utenti on ListFragment and not on my activity..

fabio
  • 271
  • 5
  • 18
  • 1
    *why?* - Are you sure you're not adding another fresh instance of the `Fragment` somewhere in your `Activity`? – user Mar 08 '13 at 08:23

1 Answers1

10

This can happen if you're always creating a new fragment in your Activity#onCreate() callback.
If it's true, check this answer. Your Fragment#onActivityCreated will be called twice:

  • First time triggered by FragmentActivity#onStart's call to mFragments.dispatchActivityCreated(). It will pass the saved instance.
  • Second time triggered by FragmentActivity#onStart's call to mFragments.execPendingActions(). This time without saved instance (since it is being called in response to new Fragment addition).
Community
  • 1
  • 1
Alex Lipov
  • 13,503
  • 5
  • 64
  • 87