Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlarmManager: PendingIntent gone after swiping app from recent apps on some devices

Simple demo GitHub project: https://github.com/Try4W/AlarmManagerDemo

On emulators(Android 4.1.1, Android 6):

  1. I scheduling new PendingIntent with AlarmManager
  2. check active alarms via adb shell dumpsys alarm
  3. see my Intent
  4. close app via swiping it from recent apps
  5. check active alarms via adb shell dumpsys alarm
  6. see my Intent
  7. BroadcastReciver fired at time!

On my device(LeTv One/Android 6):

  1. I scheduling new PendingIntent with AlarmManage
  2. check active alarms via adb shell dumpsys alarm
  3. see my Intent
  4. close app via swiping it from recent apps
  5. check active alarms via adb shell dumpsys alarm
  6. DO NOT see my Intent
  7. BroadcastReciver not fired at all

If I add my app to 'protected apps' Intent not removed after removing app from recent apps.

BUT! On my device AliExpress's app post notification without adding to 'protected apps'.

Note: alarm scheduled without problem on BOOT_COMPLETED

How did they achieve that?

What I already tried:

  1. set alarm via alarmManager.setAlarmClock(...)
  2. set alarm via setExactAndAllowWhileIdle(...)
  3. use intent-filter to execute BroadcastReciever
  4. set alarm from Service running in separated process
like image 254
Alexandr Avatar asked Oct 30 '22 14:10

Alexandr


1 Answers

On some (most) Android devices, swiping an app from the recents apps list is the same as force-closing it from the Apps settings screen.

Android assumes this means the user doesn't want any activity from this app until further notice, which means manually launching on the app by the user.

See this: AlarmManager does not work when app is force closed

like image 181
marmor Avatar answered Nov 09 '22 03:11

marmor