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

时间:2010-06-27 17:47:38

标签: 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);

并且在Manifiest中我有强制性条目

    <receiver android:name=".MyEventReceiver"
   android:process=":remote" />

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());
        }
    }
}

当警报被激活时,即使我的应用程序没有运行,也应启动MyEventReceiver并执行某些操作。在仿真器中就是这种情况,但实际设备并非如此。

作为示例,我将在模拟器和DDMS上启动MyApplication,我可以看到MyApplication运行的过程。在MyApplication中,我添加一个警报,然后在DDMS中终止MyApplication的进程。当警报触发MyEventReceiver完成其工作并在DDMS中我看到两个进程,MyApplication和MyApplication:remote。

在实际设备上,如果我启动MyApplication,添加一个警报,然后在警报无法执行任何操作时使用任务杀手终止该进程。如果我将我的设备连接到调试器并使用DDMS而不是设备上的任务杀手来停止进程,那么警报将按照预期启动并运行。

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

1 个答案:

答案 0 :(得分:4)

  

在Manifiest我有   强制性进入

android:process=":remote"是反强制性的。请删除它。很快。

  

如果我开始在实际设备上   MyApplication,然后添加一个警报   使用任务杀手杀死进程

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

相关问题