Hi,
In an appwidget I declare a repeating alarm to refresh a widget in
every 10 seconds:
@Override
public void onUpdate(Context context, AppWidgetManager
appWidgetManager, int[] appWidgetIds) {
Intent update = new Intent(REFRESH);
PendingIntent intent = PendingIntent.getBroadcast(context, 0,
update, 0);
AlarmManager alarms =
(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarms.setRepeating(AlarmManager.RTC,
System.currentTimeMillis(), 10000, intent);
startUpdateService(context, appWidgetIds);
}
protected static int refresh = 0;
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (REFRESH.equals(intent.getAction())) {
refresh++;
AppWidgetManager mgr =
AppWidgetManager.getInstance(context);
ComponentName provider = new
ComponentName(context.getPackageName(), getClass().getName());
int[] appWidgetIds = mgr.getAppWidgetIds(provider);
startUpdateService(context, appWidgetIds);
}
}
I use AlarmManager.RTC, because I don't want my widgets to be updated
in sleep mode.
At every update I increase the "refresh" variable which counts the
number of updates. And I display this value in the widget.
The phone go sleep mode, and after a while when I use my phone again I
realize that the widget was updated
in every 10 seconds (because the variable increased in every 10
seconds).
What should I do to prevent my widgets be updated in sleep mode?
Can I detect somehow that the screen is off, or a phone is in sleep
mode? Or the phone wasn't in sleep mode? Why?
Thank you,
T.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en