I’m using a Alarm Manager through with Service for updating widget instance. While doing this, I suppose missing some important spots.
This is how I set the Alarm Manager:
public class MyWidget extends AppWidgetProvider {
public void onEnabled(Context ctx) {
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyService.class);
pi = PendingIntent.getService(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
// Repeat value depends on preferences.
Long repeat = Long.parseLong(prefs.getString("update_preference", "600"));
alarmManager.setRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime(), 1000*repeat, pi);
}
@Override
public void onDisabled(Context context) {
super.onDisabled(context);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyService.class);
PendingIntent pi = PendingIntent.getService(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.cancel(pi);
}
}
Let me explain them:
- If device got a call or make a call, Edge/3G not working well. How do I handle a call? If I could, is it a possible to restart/trigger alarm manager after the call? Or any other suggestion appreciated.
- When device asleep (a few minutes), after the unlock alarm manager works immediately even if interval value was exceed. But if asleep takes long time, after the unlock alarm manager and also widget receiver not working. What’s the way of overstepping asleep for every repeat.
- How to control reboot progress? I mean after the reboot service should be start for widget update. Not sure the way of starting.
Any help or suggestions will be great.
Some of your questions are not very clear so I’ll try and answer to the best of my understanding:
setRepeatingcall to useAlarmManager.RTC_WAKEUPinstead ofAlarmManager.RTC. Read more hereIntent.ACTION_BOOT_COMPLETED. This must be registered as a receiver on your app manifest. Read more here.