Jake,

It isn't and it doesn't.

I know it's a little counter-intuitive, but that's the case.

AppWidgetProvider is just a special BroadcastReceiver. It is instantiated by Android runtime / home screen in response to events defined in the manifest, and provides a RemoteViews object that defines widget state. After that it (its process) can get killed, and instantiated next time it is needed to handle a broadcast.

Heck, even home screen orientation changes don't cause AppWidgetProvider to be instantiated - Android just uses the most recent RemoteViews it saves somewhere.

-- Kostya

15.07.2010 20:13, Jake Colman пишет:
Kostya,

How can it be transient?  Doesn't the instance have to remain in
existence for as long as the AppWidget exists on the Home Screen?
Clearly, I can do as you suggest; I'd just like to understand why it's
necessary.

Thanks.

...Jake


"KV" == Kostya Vasilyev<[email protected]>  writes:
    KV>  Jake,

    KV>  AppWidgetProviders are transient, you can't store any data in
    KV>  these objects. They are created by Android as necessary and are
    KV>  destroyed, from what I see with my widgets, quite aggressively.

    KV>  Canceling an alarm doesn't require the same Java object you used
    KV>  to set an alarm.

    KV>  Just create another PendingIntent with the same values, and call
    KV>  cancel() with this new object.

    KV>  This will remove the need for storing data in AppWidgetProvider
    KV>  instance variables, which you can't do.

    KV>  -- Kostya

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

KV> -- KV> Kostya Vasilev -- WiFi Manager + pretty widget --
    KV>  http://kmansoft.wordpress.com

KV> -- KV> You received this message because you are subscribed to the Google
    KV>  Groups "Android Beginners" group.

    KV>  NEW! Try asking and tagging your question on Stack Overflow at
    KV>  http://stackoverflow.com/questions/tagged/android

    KV>  To unsubscribe from this group, send email to
    KV>  [email protected]
    KV>  For more options, visit this group at
    KV>  http://groups.google.com/group/android-beginners?hl=en



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

Reply via email to