I need to start the activity AlarmReceiver
after 10 seconds (for example). I need it to be activated without running the app. But whether the app runs or not the AlarmReceiver
do not get called. Any suggestions?
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 111, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
//alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
//+ (10 * 1000), pendingIntent);
Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();
As of now, it's not possible to start Alarm without running the app, you must once run your respective app to activate your alarm.. For this....!!
In Your ALARM_ACTIVITY :
In Your ALARM_RECEIVER :
So long as your app has run once to establish the alarm with
AlarmManager
, the alarm fires your intent even if your app isn't running. The exception is after a device restart. To start an alarm when the device restarts, implement aBroadcastReceiver
to set the alarm, and add the receiver to your manifest forACTION_BOOT_COMPLETED
:And if it is still not working getting rid of the
android:process=":remote"
part may help. Worked for me :)Also, In addition to the above,I think the methods in the AlarmActivity should be in the oncreate method of the LAUNCHER activity.. In this case, the Alarm Activvity should be the LAUNCHER activity of the app. this solved my problem
This is the final code i managed to get working. You need to add
just above the
</application>
tag in Manifest file.This will set an alarm to trigger in 30 seconds after calling the method
SetAlarm()