I have an android setInexactRepeating placed inside of my onCreate that never fires. I have a log inside of it to make sure that it's actually executing, and that doesn't seem to fire, as well as the events that I have planned for it. I want it to go off every 10 seconds, but it doesn't even seem to go off even the first time.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("Restart", "First");
Intent toRun = new Intent(this, AlarmRestart.class);
PendingIntent pendingToRun = PendingIntent.getBroadcast(this, 0, toRun, 0);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.cancel(pendingToRun);
am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, System.currentTimeMillis(), 10000L, pendingToRun);
Log.d("Restart", "Second");
}
This is in the other file:
public class AlarmRestart extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Log.d("Restart", "Third");
}
}
This is what "adb shell dumpsys alarm" says
com.packageName.restart
5715ms running, 64 wakeups
3 alarms: flg=0x14 cmp=com.packageName.restart/.AlarmRestart
61 alarms: flg=0x14 cmp=com.packageName.restart/.reciever.AlarmRestart
AlarmRestart
is a BroadcastReceiver
. It is not a Service
. Yet you are trying to use a getService()
PendingIntent
. That will not work. Change getService()
to getBroadcast()
, and you should have better luck.
I found the problem :/
<reciever android:name="com.appName.restart.AlarmRestart" android:enabled="true" />
It's spelled receiver....not reciever. Seriously, XML needs an error checker. I'm still marking CommonWares answer as the accepted one, because he solved several other issues that I would have run into later.
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