2

I want to run a task in my app everyday, I am using JobScheduler for it and works fine in stock OS, but when I try to run it in phones which has custom ROM (Xiaomi) it doesn't work unless I explicitly enable auto-start option for the app in security. Is there any solution for this, how are other apps handling this scenario ?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
AndroidDev
  • 1,485
  • 2
  • 18
  • 33
  • Without auto-start enable, you can not run any background service because of battery optimization – Sniffer Oct 22 '18 at 10:49
  • @Sniffer, Then how are other apps able to mange ? (What's app to backup message everyday, Alarm app's to run alarm) – AndroidDev Oct 22 '18 at 11:02
  • Check [this](https://android.stackexchange.com/a/140782/274967) ,I hope you got the point – Sniffer Oct 22 '18 at 11:04
  • workmanager manages this it looks at the version of OS and select manager accordingly.. so you should try WORKMANAGER – Adeel Turk Oct 22 '18 at 11:07
  • 1
    @AdeelTurk, WorkManger is still in alpha and has lot of issues surrounding it. Few people strictly don't recommend it. Is there any other way ? Is this common problem that others are facing as well (or) am I missing anything with the job scheduler. – AndroidDev Oct 22 '18 at 12:25

2 Answers2

5

This is a known issue with some Android OEM that heavily modify this part of Android for battery optimization.

Aside having you application added to the whitelist, you can really only report the issue:

  • to the OEM (Xiaomi in this case) to avoid this kind of breaking changes.
  • to Google, to add a test in the CTS and avoid these behaviours by the OEMs.

Using WorkManager is not going to solve this problem because WM still uses JobScheduler API when it's available.
From WorkManager's issue tracker: are the Chinese manufacturers (Huawei, Oppo, Xiaomi...) supported?

pfmaggi
  • 6,116
  • 22
  • 43
  • this is definitely frustrating. they disabled receiving internet connectivity broadcasts from nougat onwards. and then we're forced to use workmanager but then this issue. tsk – chitgoks Jun 07 '20 at 02:43
2

Use WorkManager from now on. It will handle every thing automatically depending on the Android version

Soheil Setayeshi
  • 2,343
  • 2
  • 31
  • 43