Android - Lifecycle and saving an Instance State questions

Posted by The Salt on Stack Overflow See other posts from Stack Overflow or by The Salt
Published on 2010-04-20T16:34:06Z Indexed on 2010/04/20 18:43 UTC
Read the original article Hit count: 308

Filed under:
|

So within my application is a form for creating a new user, with relevant details and information about the user. There's no problems there, it's just what happens when the user leaves the activity without pressing the confirm button.

Here's what I want to do:

  1. If the user presses the back button, attempt to save all the data to the database and inform the user.
  2. If the activity is interrupted (ie by a phone call), save all the data into a temporary location so when the activity is at the top of the stack again, nothing appears to have changed (but the data still hasn't yet been saved to the database).
  3. If the activity gets killed for more resources when in the background, do the same as point 2 above (ie when the activity is started again, it appears that nothing has changed).
  4. If the whole application is started again (by clicking on the icon again) and there is temporary data stored from either points 2 or 3 above, navigate to the "create user" activity and display data as if nothings changed.

Here's how I'm currently trying to do it:

  • Use onDestroy() and isFinishing() functions to find when the activity is being killed, to cover point 1 above (to then try and save all data).
  • Save all data with onSaveInstanceState into a bundle (to cover point 2 above)
  • Does the bundle created with onSaveInstanceState survive the activity being killed for more resources, so when its recreated the previous state can be retrieved (as in point 3 above)?
  • No idea how to implement point 4.

Any help would be massively appreciated.

Cheers!

© Stack Overflow or respective owner

Related posts about android

Related posts about lifecycle