Saved state exception
android
Solution
I ran into this same problem, I believe it a bug with android. Take a look at this thread for a possible solution http://code.google.com/p/android/issues/detail?id=22404
Problem
I'm getting the following exception with my app. I believe this happens when the user leaves the app for a long time then returns to it. I am unable to replicate it however it is showing up in my crash logs a lot. I have no idea why this is happening so any suggestions are greatly appreciated. ``` java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.MyActivity}: java.lang.ArrayIndexOutOfBoundsException: length=3; index=-1 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2237) at android.app.ActivityThread.access$600(ActivityThread.java:139) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:4974) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=-1 at java.util.ArrayList.get(ArrayList.java:306) at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1764) at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:198) at com.myapp.MyActivity.onCreate(MyActivity.java:235) at android.app.Activity.performCreate(Activity.java:4538) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2158) ... 11 more ``` Line 235 is the following: ``` @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // line 235 ``` My onSaveInstanceState() is pretty simple: ``` @Override public void onSaveInstanceState(Bundle state) { super.onSaveInstanceState(state); state.putInt("id1", id1); state.putInt("id2", id2); state.putInt("id3", id3); state.putInt("id4", id4); } ```