AlarmManager 在模拟器中触发但不在物理设备上触发

JDM*_*JDM 3 android broadcastreceiver alarmmanager

我有一个调用 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);
Run Code Online (Sandbox Code Playgroud)

在 Manifyingt 中,我有强制性条目

    <receiver android:name=".MyEventReceiver"
   android:process=":remote" />
Run Code Online (Sandbox Code Playgroud)

MyEventReceiver 看起来像这样

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());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当警报被激活时,即使我的应用程序没有运行,也应该启动 MyEventReceiver 并做一些事情。在模拟器中是这种情况,但在实际设备上却并非如此。

例如,我将在模拟器上启动 MyApplication,在 DDMS 中我可以看到 MyApplication 运行的过程。在 MyApplication 中,我添加了一个警报,然后在 DDMS 中终止了 MyApplication 的进程。当警报触发 MyEventReceiver 时,我会在 DDMS 中看到两个进程,MyApplication 和 MyApplication:remote。

在实际设备上,如果我启动 MyApplication,添加一个警报,然后在警报执行的时间到来时使用任务杀手终止进程,什么也没有发生。如果我将我的设备连接到调试器并使用 DDMS 而不是设备上的任务杀手来停止进程,那么警报将触发并按预期工作。

有人能帮我理解为什么会这样吗?我的印象是,一旦安排了警报,除非重新启动设备,否则它将持续存在。设备在应执行警报时处于唤醒状态。

Com*_*are 5

在 Manifyingt 中,我有强制性条目

android:process=":remote"是反义务的。请删除它。迅速地。

在实际设备上,如果我启动 MyApplication,添加警报,然后使用任务杀手终止进程

任务杀手也会删除应用程序的警报,但此问题已在 Android 2.2 中解决。