Mark,

Thanks for your usual spot-on reply.  Now I'm getting somewhere.

   >> If that is the case, what would cause that to happen given that my
   >> appwidget is regularly using the service?

   MM> A service in support of an app widget, IMHO, should not be trying
   MM> to live forever. It should be an IntentService, to do a little
   MM> bit of work, then get the heck out of RAM.

An "IntentService" as opposed to what?  Feel free to tell me RTFM and
point me to the right place.

My appwidget currently does the following to start or invoke the
service:

context.startService( new Intent( context, ZMUpdateService.class ) );

I can see that the service's onCreate() method is called the first time
I do this and its onStart() method is called each subsequent time.  How
do I set up the service "to do a little bit of work, then get the heck
out of RAM"?  I have the "little bit of work" part down pat since the
service does seem to do its job.  But what else are you suggesting?

   >> And if this is something I have to deal with, how do I preserve
   >> state across this situation?

   MM> Files. Databases.

Can you please provide a little bit of color here?  Again, RTFM is fine.
All I really need to track is the state of three simple variables.

   >>  And how do I distinguish between the service being destroyed
   >> because Android chose to do it (in which case I need to preserve
   >> my state) and it being destroyed because the widget was deleted
   >> from the homescreen (in which case I do not need to preserve my
   >> state)?

   MM> Implement the appropriate methods in AppWidgetProvider to
   MM> determine when the app widget is deleted. You will need the
   MM> corresponding actions in your <intent-filter> for the
   MM> AppWidgetProvider as well, IIRC.

The appwidget already implements onDeleted() so as to cancel the alarm
used to trigger the service and to explicitly stop the service.  I guess
I would use this method to clean up the persisted data from the service
so that, upon a reinstall/restart the service starts fresh.

-- 
Jake Colman -- Android Tinkerer

-- 
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