Streets is right, and gives good practical advice, as usual. I do the same, if it's important, it has a getter and a setter. The getter checks for null, if it's null it gets from local storage, be it a preference, a file, an sqlite db, or it makes a new network call. Then it gets set to local storage.
I do this with the response from most network calls, but definitely the first important one. Also with any user preference set in settings, etc. On Mar 9, 1:37 pm, Streets Of Boston <[email protected]> wrote: > Try to avoid subclassing the Application class. > Just use static variables. Initialize them to null/0/whatever and > check them in the onCreate of your activity. If these are null/0/ > whatever, initialize these static variable properly and continue. But > re-initializing them *won't maintain* state. After you process has > been killed, your state is reset. You can use static variables to > share state between multiple activities in your app (as long as > they're started in the same process). > > If you want to maintain state over configuration changes (e.g. slide > out keyboard, orientation changes), use the activity's > onRetainNonConfigurationInstance method. > > If you want to maintain state even if your process has been killed, > use the activity's onSaveInstanceState method (and related methods). > > On Mar 9, 5:59 am, miguelo <[email protected]> wrote: > > > > > Hi, thanks for your help. I have read about how to save and restore > > the status of an activity (onSavedInstanceState(), > > onRestoreInstanceState(), ...) > > > My problem is I'm extending the android.app.Application class, which > > is a "base class for those who need to maintain global application > > state" and I'm using it to maintain some global data (user logged in, > > DB helper, ...). These are the data I'm losing if I leave my > > application opened and after a few hours I return to it. I'm able to > > restore the specific data of the running activity but not these global > > data. > > > I don't know if I'm using a bad practice (and in that case which is > > the recommended approach to store global application state), and if > > that's the correct place to do it, how can I save/restore those data > > when my process is killed/restarted. > > > Thanks, > > > Miguel > > > On 8 mar, 17:22, TreKing <[email protected]> wrote: > > ... > > > > Did you readed about onSavedInstanceState and onRestoreInstanceState ? > > > ... -- 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

