简体   繁体   English

AlarmManager在仿真器中触发,但不在物理设备上触发

[英]AlarmManager firing in emulator but not on physical device

I have an application that calls 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);

and in the Manifiest I have the obligatory entry 在Manifiedt中,我必须输入

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

MyEventReceiver looks like this 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());
        }
    }
}

When the alarm is activated MyEventReceiver should be started and do something even if my application is not running. 激活警报后,即使我的应用程序未运行,也应启动MyEventReceiver并执行某些操作。 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. 作为示例,我将在模拟器上启动MyApplication,在DDMS中,我可以看到MyApplication运行的过程。 From within MyApplication I add an alarm and then within DDMS kill the process for MyApplication. 在MyApplication中,我添加了一个警报,然后在DDMS中终止了MyApplication的进程。 When the alarm fires MyEventReceiver does its work and in DDMS I see two processes, MyApplication, and MyApplication:remote. 当警报触发MyEventReceiver起作用时,在DDMS中,我看到两个进程,MyApplication和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. 在实际的设备上,如果我启动MyApplication,请添加警报,然后在警报执行任何时间的情况下使用任务杀手杀死该进程。 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. 如果我将设备连接到调试器并使用DDMS而不是设备上的任务杀手来停止该过程,则警报将按预期方式触发并工作。

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. 警报执行时设备处于唤醒状态。

and in the Manifiest I have the obligatory entry 在Manifiedt中,我必须输入

android:process=":remote" is anti-obligatory. android:process=":remote"是强制性的。 Please remove it. 请删除它。 Quickly. 很快。

On an actual device if I start MyApplication, add an alarm and then kill the process using a task killer 在实际设备上,如果我启动MyApplication,请添加警报,然后使用任务杀手杀死该进程

Task killers remove the app's alarms as well, though this issue is resolved with Android 2.2. 尽管Android 2.2可以解决此问题,但任务杀手也可以删除该应用的警报。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM