问题
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 ?
回答1:
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?
回答2:
Use WorkManager from now on. It will handle every thing automatically depending on the Android version
来源:https://stackoverflow.com/questions/52927465/jobscheduler-is-not-working-in-xiaomi-when-app-is-not-in-background-and-auto-sta