I have an ArrayList<> of a custom Object that I need to save when my users close down my app. I can see in logcat that it "saves" it to outBundle when I use Bundle.putParcelableArrayList, but it doesn't recover it when I start the app again, either with Genymotion or physical phone. I also can't cast the final String to Serializable for whatever reason if that would help.
static final String tasks = "tasks";
outState.putParcelableArrayList(tasks, taskList); //this works
taskList = savedInstanceState.getParcelableArrayList(tasks); //this doesn't
I've tried calling it in onCreate with a (savedInstanceState != null) statement and in onRestoreInstanceState.
Am I missing something obvious here?
EDIT: this is what I want to see in logCat:
outState.putParcelableArrayList(tasks, taskList);
System.out.println("saved: " + taskList);
And this is what I get:
04-15 09:24:27.513 1791-1791/com.aau.uni.mea2015.a317b.cueless I/System.out﹕ saved: [this is a task
04-15 09:24:27.513 1791-1791/com.aau.uni.mea2015.a317b.cueless I/System.out﹕ 0 - 1 minutter, 1 underopgave(r)]
There is no logcat output for onRestore or onCreate because it never "plays" it. /edit
From what I read here "... that I need to save when my users close down my app. ... but it doesn't recover it when I start the app again, either with Genymotion or physical phone." it sounds like you are closing the app manually.
This way onRestoreInstanceState() won't be called. It is only called if the activity has been killed by the OS.
Check this post or this SO post as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With