guich wrote:
> When the user press the home key, the onPause method is called. At
> this time, the application is supposed to save its state so it can be
> properly recovered later.

That depends on what state you are referring to. onSaveInstanceState()
is for data that is transient. onPause() might be a spot to save data
that is more persistent.

> Is there a safer place to put a "save everything and quit" code so
> that it can safely save everything before a "kill the activity" task
> is issued?

Yes: when the user pushes the "Save" button on the Save menu choice or
something, use an AsyncTask or IntentService to persist your changes.

Having the BACK button or something imply a "save" operation is OK when
everything is local. If you need Internet access, though, I would not
use the BACK button as the "save" trigger. After all, if you have no
Internet connection, you can disable the Save button/menu choice, but
you cannot realistically disable the BACK button.

In a pinch, fire off an AsyncTask or use an IntentService to persist
your data on an Android-supplied background thread. However, if you are
not finishing (i.e., isFinishing() is false), you probably also want to
cache that data locally, since you may need it in a few milliseconds and
should not be waiting both to persist the data to the Internet and then
read it back again.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android Training in US: 14-18 June 2010: http://bignerdranch.com

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to