gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:35:14 24 4
gpt4 key购买 nike

我有一个调用 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);

在 list 中我有强制性条目

    <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 也应该启动并做一些事情。在模拟器中是这种情况,但在实际设备上并非如此。

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

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

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

最佳答案

and in the Manifiest I have the obligatory entry

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

On an actual device if I start MyApplication, add an alarm and then kill the process using a task killer

Task killers 也删除了应用程序的警报,尽管这个问题在 Android 2.2 中得到了解决。

关于android - AlarmManager 在模拟器中触发但不在物理设备上触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26682227/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com