I have an application that calls AlarmManager
Intent intent;
intent = new Intent(context, MyEventReceiver.class);
PendingIntent appIntent = PendingIntent.getBroadcast(context, 0,
intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
appIntent);
and in the Manifiest I have the obligatory entry
<receiver android:name=".MyEventReceiver"
android:process=":remote" />
MyEventReceiver looks like this
public class MyEventReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
try
{
// DO SOME WORK
}
catch (Exception e)
{
Log.e("MyEventReceiver", e.getMessage().toString());
}
}
}
When the alarm is activated MyEventReceiver should be started and do something even if my application is not running. In the emulator this is the case however on the actual device this is not the case.
As an example I will start MyApplication on the emulator and in DDMS I can see the process for MyApplication running. From within MyApplication I add an alarm and then within DDMS kill the process for MyApplication. When the alarm fires MyEventReceiver does its work and in DDMS I see two processes, MyApplication, and MyApplication:remote.
On an actual device if I start MyApplication, add an alarm and then kill the process using a task killer when the time comes for the alarm to execute nothing happens. If I connect my device to the debugger and stop the process using DDMS instead of the task killer on the device then the alarm will fire and work as expected.
Can someone help me understand why this is happening? I was under the impression that once the alarm was scheduled it would persist unless the device were rebooted. The device is awake at the time the alarm should execute.