简体   繁体   中英

AlarmManager Android 4.4.2 bug

In my app I have a service and I use AlarmManager in this way:

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.

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). 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; plus all the code in the service remains like stuck. So my app stops working but service remains in the 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. 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!

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. It's just me or this happens to all 4.4.2 android versions?

Starting android 4.4 you have to use setExact() in order to execute alarms in accurate time.
Otherwise it'z the OS decision when to execute your alarm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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