I have developed android app in which i am running foreground service and it fetches the user current location and send it to server after user changes its location or if user doesn't change its location then it pushes the current location every 5 minutes. Now the scenario is; on Huawei phones I've noticed issue. Whenever i lock my phone then the Huawei OS stops the foreground GPS service and location doesn't send to the server which creates issues for me. I've tried all the solutions available on stack-overflow but didn't succeeded an
-
Does this answer your question? [Service stops working after sometime. Needed to work continuously](https://stackoverflow.com/questions/44535567/service-stops-working-after-sometime-needed-to-work-continuously) – Calaf Jul 19 '20 at 11:14
-
No this is not the answer. Actually my app is working fine but it gives issue only on huawei devices and i am using Y5 – Junaid Durrani Jul 19 '20 at 11:22
1 Answers
This happens because of Doze mode, here you can read about Android Doze Mode https://developer.android.com/training/monitoring-device-state/doze-standby
and you can use Work Manager for your purpose: https://developer.android.com/topic/libraries/architecture/workmanager
WorkManager allows you to schedule work to run one- time or repeatedly using flexible scheduling windows. Work can be tagged and named as well, allowing you to schedule unique, replaceable, work and monitor or cancel groups of work together. Scheduled work is stored in an internally managed SQLite database and WorkManager takes care of ensuring that this work persists and is rescheduled across device reboots. In addition, WorkManager adheres to power-saving features and best practices like Doze mode, so you don’t have to worry about it.

- 692
- 6
- 13