2

I am developing an android app which uses alarm manager's setrepeating method for setting repeat alarms and then showing notifications though onreceive of the receiver when the alarm triggers.But there is a problem.
When I swipe the app off from the devices like Samsung Galaxy,it works well and notifies through alarm but in Le2,the alarm is destroyed and hence the notification is not shown.Even if I open the app again,the old alarm set is lost.I went through many answers but those just tell about the device problem(Le2) that force stops the app when swiped.None of the answers gave a good solution.

Vignesh R
  • 23
  • 2
  • You should maintain your alarm in database when the device turned off ...and again should set the alarm by the database values............Or it may be device manufacturers problem when app is swiped off – Ko Vartthan Apr 26 '17 at 05:20
  • This can be due to the device, if device doesn't have enough memory to perform its basics tasks by operating system , it stops the other tasks that consumes memory. – Abdul Kawee Apr 26 '17 at 05:21
  • Yea its the device problem as most Chinese vendors try to optimise battery and they do these stupid things like force stopping through swipe from recent apps. Is there any way i can overcome this ? @KoVartthan That seems a good option but is there any better way like using services? – Vignesh R Apr 26 '17 at 06:26
  • 1. Save all your alarm in db 2. When an alarm finished ,delete from db 3. When you swipe the app , the alarm gets clear , so when starting your application set again the alarm by retrieving the values from db ........it may helps you.........play with the life cycle activity methods in android..... – Ko Vartthan Apr 26 '17 at 06:33
  • 1
    see the section about alarm managers for doze mode....https://developer.android.com/training/monitoring-device-state/doze-standby.html – Opiatefuchs Apr 26 '17 at 06:43
  • @Opiatefuchs if doze mode is off in the device , alarm will run in background ? – Ko Vartthan Apr 26 '17 at 09:02
  • @Ko ....usually I would say yes, but from my experience doze mode is unpredictable and also up to the device how it is implemented. Some devices fall as soon into doze mode as the screen goes off, some does need some time. I made much experiments with many devices and I found out it´s not following strict rules as it should. So, you can´t say 100% that the device is in doze mode or not. – Opiatefuchs Apr 26 '17 at 09:20
  • additional: next to doze mode, some devices have their own energy management that works additional to doze mode, so you have to be aware of both. The integration of Doze mode was a bad idea, it should protect the device from energy waste, but there is no possibility for the user to disable it. And exactly that is the point which makes the doze mode user and developer unfriendly... – Opiatefuchs Apr 26 '17 at 09:21
  • These features push developers into the trouble ...............Thank u for your info :) @Opiatefuchs – Ko Vartthan Apr 26 '17 at 09:23

2 Answers2

1

Some of the phone manufacturers e.g. XiaoMi and MeiZu disallow the application from running in the background unless user allow it.

For XiaoMi, user can grant the access to app by adding it to AutoStart list. If not mistaken, Le2 has same function in the "App Protection" under phone manager app.

Fernando Tan
  • 634
  • 4
  • 14
  • I don't think so because alarms are registered with the OS. – Muhammad Babar Apr 26 '17 at 06:39
  • I am pretty sure that XiaoMi disables all background services and alarm managers by default. It only enable for certain famous apps e.g. whatsapp. Other apps require user explicitly add it into AutoStart list. This is something similar in the Le2 and there must be some way to enable it, e.g. "App Protection" setting. – Fernando Tan Apr 26 '17 at 06:43
  • I have seen this behavior with background services but not sure if they have tweaked the behavior for Alarms too. Because alarms can run even if the app is not running. – Muhammad Babar Apr 26 '17 at 06:46
  • Sounds interesting ......... developer point of view is okay but how normal users know this all sort if things @FernandoTan – Ko Vartthan Apr 26 '17 at 09:04
  • @Muhammad...well Fernando is right. Even Huawei has this stuff, it´s called TelephonyManager. There are a view options where you have to whitelist your app (not only one), if it is not, your app does nothing. I don´t know why some manufacturers do something like this. At the end, we as developers get blamed by the users, because they think it´s our fault. – Opiatefuchs Apr 26 '17 at 11:35
0

Got it. In Leeco LE2, just go to settings -> battery -> power saving management -> app protection and disable your app for auto cleaning. Works now. It's because the manufacturer has messed up lot of things to improve battery life and hence has become nightmare for developers to catch the solution.

Vignesh R
  • 23
  • 2
  • This might be the solution but not for LeEco yet, https://stackoverflow.com/questions/38995469/how-to-get-miui-security-app-auto-start-permission-programmatically – Ivor Jan 29 '18 at 10:40