I'm going to create widget which needs to update its content every minute (it shows time-related data).
However, there is no need to update widget if it is currently invisible, which means:
What is the best way to update only visible widget every minute - without waking up device nor doing unnecessary computations? After widget becomes visible, small lag before update is acceptable.
Full update: Call AppWidgetManager. updateAppWidget(int, android. widget. RemoteViews) to fully update the widget.
The most common reason for a widget to disappear is when Android users transfer applications to a memory card. Widgets may also disappear after the hard reboot of your device. To return it, you need to transfer them again to the phone's memory.
Widgets are now in the Apps list. Open your app drawer and you'll see them. Some of the apps may not have ICS compatible apps. Just check for updates for your apps and see if that resolves it.
To keep from updating when the screen is off, use the AlarmManager to schedule a recurring alarm that doesn't wakeup the phone.
The other two bullet points you have in your question aren't possible. There is no way to detect if your widget is on a home screen that isn't currently visible, and there is no way to determine if an app is running that is hiding the home screen. I have filed a ticket on http://b.android.com requesting this functionality be added to Android. If you feel like starring it, it will help it gain priority: http://code.google.com/p/android/issues/detail?id=5529&q=reporter:mark.r.baird&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
Allthough the answer above concerning the AlarmManager is correct it may not be sufficient since I observed many phones also delivering alarms even if they are not of type *_WAKEUP. This may happen if there are other applications installed that are waking up the device. And if it is once awake, it delivers all pending alarms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With