问题描述
我有一个调用AlarmManager应用程序
意向意图;
意图=新的意图(背景下,MyEventReceiver.class);
PendingIntent appIntent = PendingIntent.getBroadcast(上下文,0,
意图,PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager =(AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),
appIntent);
和在Manifiest我有强制性条目
<接收机器人:名称=。MyEventReceiver
机器人:工艺=:远程/>
MyEventReceiver看起来像这样
公共类MyEventReceiver扩展的BroadcastReceiver
{
@覆盖
公共无效的onReceive(上下文的背景下,意图意图)
{
尝试
{
//做一些工作
}
赶上(例外五)
{
Log.e(MyEventReceiver,e.getMessage()的toString());
}
}
}
当报警被激活MyEventReceiver应该开始做,即使我的应用程序没有运行的东西。在仿真器中,这是实际的设备本但是上的情况并非如此。
作为一个例子,我将开始所有MyApplication在模拟器上和DDMS我可以看到这个过程的所有MyApplication运行。从内所有MyApplication我想补充一个报警,然后在DDMS终止进程的所有MyApplication。当警报触发MyEventReceiver做其工作,并在DDMS我看到两道工序,所有MyApplication,和所有MyApplication:远程
在一个实际的设备,如果我开始所有MyApplication,增加一个报警,然后使用任务杀手杀死进程,在时机成熟时进行执行什么都不会发生报警。如果我在我的设备连接到调试和使用,而不是设备上的任务的杀手DDMS则如预期的报警触发和工作进程停止。
有人可以帮助我了解为什么发生这种情况?我下的是IM pression,一旦报警定会再接再厉,除非该设备被重新启动。该设备是醒着的时候报警应该执行。
安卓程序=:远程
是抗强制性。请删除它。快。
任务的杀手删除应用程序的报警为好,但这个问题解决了Android 2.2。
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.
android:process=":remote"
is anti-obligatory. Please remove it. Quickly.
Task killers remove the app's alarms as well, though this issue is resolved with Android 2.2.
这篇关于AlarmManager射击模拟器,但不是在物理设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!