I have a service (properly declared in the Manifest file) that upon onDestroy()
schedules itself to start again one minute later via AlarmManager
. However the service is not starting even though onDestroy()
runs correctly. What could be wrong?
The scheduling code:
@Override
public void onDestroy() {
BroadcastReceiver br = new BroadcastReceiver() {
@Override
public void onReceive(Context c, Intent i) {
c.startService(new Intent(c, MyService.class));
}
};
registerReceiver(br, new IntentFilter("xxxx"));
PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent("xxxx"), 0);
AlarmManager am = (AlarmManager)(this.getSystemService(Context.ALARM_SERVICE));
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + ONE_MINUTE, pi);
Log.i("onDestroy", "Service scheduled.");
unregisterReceiver(br);
super.onDestroy();
}
The service declaration in the Manifest file:
<service
android:name="com.xxxx.MyService"
android:exported="true">
</service>