Ok. Lets say that it goes into a static singleton, and say the status is level2 and the application/widget gets shutdown. I suppose I would need to implement a saveState() method on the singleton, and detect this shutdown somewhere so I could recover the correct state? I don't think there is any method on the Application that is guaranteed to get called during such a shutdown. There is terminate method but this is not really called for sure. The widget is long running, so where would be the best place to save off the application status/state during shutdown? or when process gets killed.
Thanks On Feb 5, 3:03 pm, Kostya Vasilyev <[email protected]> wrote: > You can use a lazy initialize Java Singleton, where you pass in a context in > case one is needed to recreate state. > > If you need to keep a context reference, make sure to call > getApplicationContext and keep that instead, so you don't run into object > lifetime issues and leak memory (in case that Context is an Activity or a > Service, and it goes away before the process does). > > The stuff about not doing much in the application's onCreate I take to be > more of an architectural suggestion than a real framework limitation, you > can probably do as much there as in any other callback (e.g activity > onCreate), subject to ANR timeouts. > > -- > Kostya Vasilyev --http://kmansoft.wordpress.com > 06.02.2011 1:38 пользователь "AndroidDevTime" <[email protected]> > написал: > > > I have an Widget Application that also has Activities, and a heavily > > used Service full of functions. I would like to keep a global status > > for the application. This is app/widget specific state like say > > STARTED, LEVEL1, LEVEL2 etc, so since the status is referenced in the > > widget, the service, and activities I thought a static variable in an > > Application Subclass might be good. So my question is twofold. > > > 1) Where should I keep such a state/status variable as a syncronized > > static variable in an application subclass? > > > And > > > 2) Its first initial value depends on reading some values by calling > > registerReceiver(null, intent) passing null for the receiver in order > > to obtain some system values. Where should I do this initialization. > > The Application.onCreate() docs indicate that not much should happen > > in this method. I am thinking in the Widget.update method can call > > getApplication and perform the registerReceiver operation and then > > update the static variable in the Applicaiton subclass. Is this the > > right place to initialize the application state? > > > Thanks > > > -- > > 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]<android-developers%[email protected]> > > For more options, visit this group at > >http://groups.google.com/group/android-developers?hl=en -- 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

