Jake,
AppWidgetProviders are transient, you can't store any data in these
objects. They are created by Android as necessary and are destroyed,
from what I see with my widgets, quite aggressively.
Canceling an alarm doesn't require the same Java object you used to set
an alarm.
Just create another PendingIntent with the same values, and call
cancel() with this new object.
This will remove the need for storing data in AppWidgetProvider instance
variables, which you can't do.
-- Kostya
15.07.2010 19:53, Jake Colman пишет:
My AppWidget's onEnabled method creates two PendingIntents. The first
is to get location updates and the second is for an ELAPSED_REALTIME
alarm. The two PendingIntents are declared as private class-level
variables so that I can access them later from different methods
(obviously). I'm having trouble canceling these PendingIntents and it
looks like its because the variable has become null. In the case of
location updates, I crash when I execute LocationManager.removeUpdates.
In the case of the alarm, I do not crash but the alarm is not canceled.
I tried putting my cancel code in onDisabled and onDeleted (not at the
same time) but it didn't work. Any suggestions?
My code looks as follows:
public void onDeleted(Context context, int[] AppWidgetIds) {
Log.d("ZMAppWidget", "onDeleted");
// cancel location updates
LocationManager lm = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
lm.removeUpdates(piLocation);
// cancel the alarm used to update the time
AlarmManager alarms = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
alarms.cancel(piAlarm);
}
Thanks.
--
Kostya Vasilev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en