onSaveInstanceState() Challenge request

Hi guys, did someone find a solution for the process death challenge??

i tried to do this but i must send the view model containing the questionBank in order to get all the information after the process death, but untill now i cant find a working solution

Hi …
The problem with process death is that it deletes the Quiz ViewModel class, so all the questions and answers are gone. I’ve added a third variable to the Question class, indicating whether the user cheated on that particular question. So it all works as long as process death doesn’t happen.

If process death happens, the entire Quiz ViewModel is gone and it gets recreated afresh when the Main activity comes back into view. So one way (which is not correct) is to store the cheats per question in the Bundle (onSaveInstanceState). This might work for small data (simple true/false whether the user cheated), but for larger data objects this is not gonna work.

I think to get this working, one must store the data in persistent memory, outside the ViewModel class … so store the Quiz ViewModel in persistent memory… and reload it when the MainActivity starts up…

a suggestion i got: if you don’t need to remember the values between application sessions, you could use Fragments instead of Activities; i.e. use a single Activity to host all the Fragments and scope the ViewModel to the Activity instead of the Fragments. This is recommended by the Android team anyway (single Activity architecture).