5

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
Alexandr
  • 3,859
  • 5
  • 32
  • 56
  • 1
    Some phone manufacturers that utilize 'protected apps' have popular and trusted apps added to the list automatically – Nick Friskel Dec 30 '16 at 08:56
  • @nickfriskel it's strange behavior. How third-party alarm apps works without being in 'whitelist'? – Alexandr Jan 05 '17 at 17:34
  • @Alexandr - did you find a solution to this ? I would like to do something similar, but OnePlus 5T is clearing the alarms when app is swiped. And yet, whatsapp, telegram, calendar etc are able to work fine even when swiped off. How do they manage this ? – Kira Jun 20 '18 at 04:46
  • Telegram and Whatsapp uses push-notifications via dedicated server which will work even If you swipe out your app from recent. I think calendar in this case is the system app which is added to system's whitelist. You can: 1. Force users to add your app to 'protected apps' aka whitelist 2. use push notifications when it can be done – Alexandr Jun 20 '18 at 06:27

1 Answers1

2

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

Community
  • 1
  • 1
marmor
  • 27,641
  • 11
  • 107
  • 150
  • app's boot BroadcastReceiver called without problems. Moreover, It successful schedule new alarm. – Alexandr Jan 05 '17 at 18:26
  • Such apps like `MyTherapy Meds` works without adding to 'protected apps' even after swiping an app from the recent apps. I decompile it's apk and can't find any special thing in scheduling their alarms. – Alexandr Jan 05 '17 at 18:27
  • 1
    Of course, `BroadcastReceiver`s will wake your app up, as well as lots of other Android ecosystem intents. Only the AlarmManager alarms are an issue. You can register to a frequently called broadcast on the phone and re-schedule your alarms if you detect you were probably force closed before. – marmor Jan 05 '17 at 18:29
  • 1
    Oh! It's sounds like great idea, thanks! What actions do you recommend to listen? – Alexandr Jan 05 '17 at 18:33
  • the user specifically mentions `after swiping app from recent apps` that is code for "force close" the app on MOST android devices, chinese or other. – marmor Feb 23 '20 at 14:40