Reputation: 2630
I am updating my AppWidgets using a Service which listens to a pub/sub channel and essentially runs in the background forever, updating the AppWidgets whenever an update is received.
I am not concerned about battery life because the device is always plugged in, but I am concerned about CPU and memory usage by these background processes.
Is there a way I can get a notification that the AppWidget is no longer visible (e.g. when the home screen goes away or is swiped to another page)? I want to be able to toggle listening to the pub/sub channel if the AppWidget is not visible.
[Added] Or, is there even a synchronous method I can call to check whether an AppWidget is currently visible?
Upvotes: 3
Views: 857
Reputation: 80340
There are ACTION_APPWIDGET_DELETED and ACTION_APPWIDGET_DISABLED broadcasts that tell when widget is deleted.
Alternatively you can also use AppWidgetProvider wrapper and implement onDelete()
and onDisable()
methods.
Upvotes: 1