I have a ToDoItem.java class and in my mainActivity class i have an arraylist in type of ToDoItem. I mean i have a "ArrayList(ToDoItem) listItems". I want to protect my arraylist in case of any configuration change. For this reason i want to use onSaveInstanceState function but in outState.(...) part i couldn't find any suitable function for my arraylist type. Can someone help me about how to save my arraylist? Thank you in advance.
Here is the code that i tried:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(savedInstanceState == null)
{
listItems = new ArrayList<ToDoItem>();
}
else
{
listItems = savedInstanceState.getStringArrayList("datas2");//problem in this line
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
outState.putStringArrayList("datas2", listItems); //problem in this line
}
logcat when i use outState.putSerializable("datas2", listItems):
11-12 17:44:44.565: E/AndroidRuntime(1321): FATAL EXCEPTION: main
11-12 17:44:44.565: E/AndroidRuntime(1321): java.lang.RuntimeException: Parcel: unable to marshal value 0 burcu 12-11-2013 NOT DONE
11-12 17:44:44.565: E/AndroidRuntime(1321): at android.os.Parcel.writeValue(Parcel.java:1235)
11-12 17:44:44.565: E/AndroidRuntime(1321): at android.os.Parcel.writeList(Parcel.java:622)
11-12 17:44:44.565: E/AndroidRuntime(1321): at android.os.Parcel.writeValue(Parcel.java:1195)
11-12 17:44:44.565: E/AndroidRuntime(1321): at android.os.Parcel.writeMapInternal(Parcel.java:591)
11-12 17:44:44.565: E/AndroidRuntime(1321): at android.os.Bundle.writeToParcel(Bundle.java:1646)
11-12 17:44:44.565: E/AndroidRuntime(1321): at android.os.Parcel.writeBundle(Parcel.java:605)
11-12 17:44:44.565: E/AndroidRuntime(1321): at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2318)
11-12 17:44:44.565: E/AndroidRuntime(1321): at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3100)
11-12 17:44:44.565: E/AndroidRuntime(1321): at android.os.Handler.handleCallback(Handler.java:730)
11-12 17:44:44.565: E/AndroidRuntime(1321): at android.os.Handler.dispatchMessage(Handler.java:92)
11-12 17:44:44.565: E/AndroidRuntime(1321): at android.os.Looper.loop(Looper.java:137)
11-12 17:44:44.565: E/AndroidRuntime(1321): at android.app.ActivityThread.main(ActivityThread.java:5103)
11-12 17:44:44.565: E/AndroidRuntime(1321): at java.lang.reflect.Method.invokeNative(Native Method)
11-12 17:44:44.565: E/AndroidRuntime(1321): at java.lang.reflect.Method.invoke(Method.java:525)
11-12 17:44:44.565: E/AndroidRuntime(1321): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-12 17:44:44.565: E/AndroidRuntime(1321): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-12 17:44:44.565: E/AndroidRuntime(1321): at dalvik.system.NativeStart.main(Native Method)