If the widget initialization requires some calls to registerReceiver() passing a null pointer to get the values where is the best place to be doing this. In my case, I am maintaining "Application state" in an Application subclass. In a sense my whole widget application has a state. The state depends on some values that I can only get by calling registerReceiver() passing the null value. The docs indicate that not much processing should go on in the Application.onCreate() method so I am not sure if this is the right place to do the initialization. On the other hand it seems like keeping Wdiget Application State in the App subclass is the right place for it,. (I also have services, and activities associated with the Widget). Where should the application state for a Widget be maintained? In the Application subclass or in the Widget itself. I have decided to put the state of the App Widget in an app subclass but not sure if this is right, given I can't very well initialize everyting in the Application.onCreate() method.
On Feb 4, 5:08 am, Mark Murphy <[email protected]> wrote: > On Fri, Feb 4, 2011 at 1:13 AM, Jeffrey <[email protected]> wrote: > > Okay, figured it out. I guess I can't have anything from the > > AppWidgetProvider class activate a registerReceiver so I have to make > > a service to do it. I don't keep it running, just launch it to update > > everything then it dies. > > If the Context passed into your onReceive() method is named ctxt, use: > > ctxt.getApplicationContext().registerReceiver(null, myIntentFilter); > > Then, you won't need service and extra overhead of starting it up. > > I just remembered that I had a blog post on this: > > http://commonsware.com/blog/2010/09/12/real-use-getapplicationcontext... > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy > > Android Training in Atlanta:http://bignerdranch.com/classes/android -- 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

