views:

55

answers:

1

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.

+1  A: 

and in the Manifiest I have the obligatory entry

android:process=":remote" is anti-obligatory. Please remove it. Quickly.

On an actual device if I start MyApplication, add an alarm and then kill the process using a task killer

Task killers remove the app's alarms as well, though this issue is resolved with Android 2.2.

CommonsWare
@CommonsWare I've seen this `:remote` here-there. What is used for and when do we need?
Pentium10
thanks for the answer Mark
@Pentium10: It forces the component (in this case, a `BroadcastReceiver`) to run in a separate process from other components. Considering how tight most Android devices are on RAM, I know of no good reason why an SDK application should be using it.
CommonsWare