AlarmManager firing in emulator but not on physical device

Deadly 提交于 2019-12-30 11:18:06

问题


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:


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.



来源:https://stackoverflow.com/questions/3128236/alarmmanager-firing-in-emulator-but-not-on-physical-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!