lujop
lujop

Reputation: 13883

Information about widget context/lifecycle

I've a widget that is packaged in an application and I've several doubts about the context/lifecycle of the widget/application:

In general any information about the widget lifecycle/context would be very apreciated

Upvotes: 0

Views: 972

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007321

The application and widget share the same process

If you look at your code, you will find a class that extends AppWidgetProvider, in all likelihood. This is the code that updates the home screen UI for the portion of it taken up by your app widget.

If you look at your manifest, you will see that you added your AppWidgetProvider as a <receiver>. This indicates that AppWidgetProvider is a BroadcastReceiver. Manifest-registered BroadcastReceivers live for a very short time -- long enough to process onReceive(), and that's about it.

Hence, it is possible that "the application and widget share the same process" momentarily, insofar as if you already have a process (e.g., the user is inside one of your activities right now), and onUpdate() of your AppWidgetProvider is triggered, then the AppWidgetProvider will be in that same process. However, if your application is not running, then onUpdate() for your AppWidgetProvider will run in some process, which may or may not have hosted any of your code before.

and consecuently singletons?

You should not rely upon this.

If I've services they have to be remote ones?

Absolutely not, for any definition of "remote".

What's the lifecycle of the process that updates the widget? Is only for the widget?

See above.

Upvotes: 1

Related Questions