This is very odd. I have a simple app which once logged in shows a fragment in an activity. The app also has an inactivity "timeout" after which time it finishes the activity and shows the login screen -- if the app is in the background when the timeout occurs then when the next onCreate
or onStart
event occurs in the activity it is finished.
However sometimes when returning to the logged in activity I get a NPE in the onActivityCreated method of my fragment. The fragment is very simple and simply calls a method on a String. The string itself is retrieved through a call to getArguments(). I have verified that whenever the Fragment is created the arguments are always set.
So it seems somehow the onActivityCreated
is actually called before onCreate
in the fragment, which I know should be impossible. Below is a portion of the stack trace:
01-14 15:34:37.176: E/AndroidRuntime(3272): at com.example.app.fragment.MyFragment.onActivityCreated(MyFragment.java:203)
01-14 15:34:37.176: E/AndroidRuntime(3272): at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1468)
01-14 15:34:37.176: E/AndroidRuntime(3272): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:931)
01-14 15:34:37.176: E/AndroidRuntime(3272): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
01-14 15:34:37.176: E/AndroidRuntime(3272): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070)
01-14 15:34:37.176: E/AndroidRuntime(3272): at android.support.v4.app.FragmentManagerImpl.dispatchReallyStop(FragmentManager.java:1888)
01-14 15:34:37.176: E/AndroidRuntime(3272): at android.support.v4.app.FragmentActivity.onReallyStop(FragmentActivity.java:787)
01-14 15:34:37.176: E/AndroidRuntime(3272): at android.support.v4.app.FragmentActivity.doReallyStop(FragmentActivity.java:764)
01-14 15:34:37.176: E/AndroidRuntime(3272): at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:322)
01-14 15:34:37.176: E/AndroidRuntime(3272): at com.actionbarsherlock.app.SherlockFragmentActivity.onDestroy(SherlockFragmentActivity.java:261)
01-14 15:34:37.176: E/AndroidRuntime(3272): at com.example.app.MyActivity.onDestroy(MyActivity.java:195)
01-14 15:34:37.176: E/AndroidRuntime(3272): at android.app.Activity.performDestroy(Activity.java:5273)
01-14 15:34:37.176: E/AndroidRuntime(3272): at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1110)
01-14 15:34:37.176: E/AndroidRuntime(3272): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3562)