Matt (preinvent) wrote: >>> The context I'm being passed may come from a service, widget update >>> request, activity or broadcast receiver (from the BATTERY_CHANGE >>> action). Can I be sure that the context points to my application in >>> all those instances? >> What else would it point to? > > That's pretty much my exact question! ie I have a broadcast receiver > that picks up battery level changes. In onRecieve, will the context > be my application, or some system context that originally sent the > broadcast message?
Ah, now I understand the question. The Context should be for your application -- I'm not aware that there even is such a thing as a "system context" that you would get your hands on. That being said, you should consider whether doing database I/O in the BroadcastReceiver's onReceive() method is the right answer. That method is being invoked with foreground priority, which means any time you spend in that method will eat CPU cycles from whatever the user is doing at the moment. For most things, that's not a problem, but it can harm the frame rates of real-time games, for example: http://www.androidguys.com/2010/03/16/code-pollution-background-foreground/ If your database I/O is going to be really really quick, perhaps leaving it in onReceive() is the best answer. Otherwise, consider delegating that work to an IntentService, where that work can be done on a true background thread. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android App Developer Books: http://commonsware.com/books -- 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

