The scenario is this, my Android app is placed in the background by the user tapping the Home button, answers an incoming call, taps a notification, etc. So, they look at Facebook, play Asphalt 8, anything that would cause the Android OS to find that it needs more memory and kill my Android app. The user decides that they want to look back at my app, tap the icon and BOINK!
When the app is started after it has been killed by the OS, the main Activity is passed a savedInstanceState that contains two keys: android:viewHierarchyState and android:support:fragments. This savedInstanceState is passed to the fragment and it crashes, stating that the fragment did not create a view:
Caused by: java.lang.IllegalStateException: Fragment com.foo.SomeFragment did not create a view.
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2200)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:404)
at android.app.Activity.setContentView(Activity.java:2156)
at com.foo.NavigationPage.onCreate(NavigationPage.java:774)
at android.app.Activity.performCreate(Activity.java:5958)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
....
So, the OS is using data it wrote the the savedInstanceState when it killed the app but for some reason, it is corrupt when the app uses it to create itself on startup.
I have tried doing this within the NavigationPage activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(null)
}
Which works for mobile app startup but if your mobile app goes into the background and you tap the icon, you expect it go come back to where you left off. Passing null causing the app to go through all its screen building/loading process which is time-consuming and not the user experience we would want.
Any thoughts on what could be happening or how I could avoid this situation?