简体   繁体   English

Android的AlarmManager 4.4.2错误

[英]AlarmManager Android 4.4.2 bug

In my app I have a service and I use AlarmManager in this way: 在我的应用程序中,我有一项服务,并且以这种方式使用AlarmManager:

AlarmManager am =(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, getIntent(), PendingIntent.FLAG_UPDATE_CURRENT);      
long mills = SystemClock.elapsedRealtime();
mills += time;   
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, mills, pi);

And here is the receiver for my intent of the am: 这是我的意图的接收者:

if (intent.getAction().equals(Timer3GOn.intentExtra)) {         
    //some code     
}

Here is how my app works: when screen goes on (i receive Intent.ACTION_USER_PRESENT ) i set an AlarmManager that after a certain amount of time sends my intent Timer3GOn.intentExtra that is received by my class. 这是我的应用程序的工作方式:屏幕打开时(我收到Intent.ACTION_USER_PRESENT ),我设置了一个AlarmManager,在经过一定时间后,该类将发送我的意图Timer3GOn.intentExtra ,该信号由班级接收。

All this works fine except in Android 4.4.2 (haven't tested in 4.4.1 yet, but in 4.4 it works well). 除了在Android 4.4.2(尚未在4.4.1中进行测试,但在4.4中运行良好)之外,所有这些功能都可以正常工作。 Only in android 4.4.2 if I delete my app from the "recent app list" of the device, the am is set properly but the intent is never received by my app; 仅在android 4.4.2中,如果我从设备的“最近的应用程序列表”中删除了我的应用程序,则am设置正确,但我的应用程序从未收到过意图; plus all the code in the service remains like stuck. 再加上服务中的所有代码仍然卡住了。 So my app stops working but service remains in the RAM. 因此我的应用程序停止工作,但服务仍保留在RAM中。

The problem doesn't start when I delete my app from recent app list, but only after I do that and the AlarmManager is set. 当我从最近的应用程序列表中删除我的应用程序时,问题不会开始,只有在我这样做并设置了AlarmManager之后,问题才开始。 How to resolve the problem? 如何解决问题?

PS in my app i have a CountDownTimer in the same class with the same context and it works well! PS在我的应用程序中,我有一个CountDownTimer在相同的类中具有相同的上下文,并且效果很好!

PPS I've noticed that whatsapp has the same problem, if you delete it from recent apps, all the incoming messages don't being delivered until i open the program. PPS我注意到,whatsapp存在相同的问题,如果您从最近的应用程序中将其删除,则直到我打开程序,所有传入的消息都不会被传递。 It's just me or this happens to all 4.4.2 android versions? 是我还是所有4.4.2 android版本都发生这种情况?

Starting android 4.4 you have to use setExact() in order to execute alarms in accurate time. 从android 4.4开始,您必须使用setExact()才能在准确的时间内执行警报。
Otherwise it'z the OS decision when to execute your alarm. 否则,由操作系统决定何时执行警报。

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

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