I'm creating an app that took coordinates every minutes and send to the server using service, but when app is in background and mobile is in idle mode it kill my service but when the phone is not in the power saving mode it doesn't kill my service, because of this scenario i have to disable the power saving mode...
Asked
Active
Viewed 6,068 times
0
-
why don't you start a sticky service even if the system kills your service it'll automatically restart it. – sumit Jul 11 '17 at 05:02
-
Refer to this [[SO Post]](https://stackoverflow.com/questions/28234502/programmatically-enable-disable-battery-saver-mode). Hope this helps. – Maraj Hussain Jul 11 '17 at 05:06
-
@ sumit.. i have done that already – Avid khan Jul 11 '17 at 05:23
-
@ Er Maraj Hussain.... i want to do that programmatically not by the user – Avid khan Jul 11 '17 at 05:25
1 Answers
1
Unfortunately you can not do such thing. And after Marshmallow android introduce Doze behavior for battery optimization which was the biggest halt seems in android for user check this out here.
Please read the above link first before approaching further. And for more information the power saver mode behavior varies device to device. I myself tested in Samsung Grand and lenovo Vibe devices . Some of Devices will not allow services in background and any network access to the application. You can find work around for the problem in android documentation in above link

ADM
- 20,406
- 11
- 52
- 83
-
Well As i said power saver mode device blocked network uses So there is no way to update the coordinate on server .What you can do if your service is running in background (as some devices won't kill Sticky services in power saver mode) , you can save coordinate in a database and Sync them to server when your application get the network access – ADM Jul 11 '17 at 05:30
-
@ ADM.... i am also done all these things..... saving coordinates in database and when the network is detected all the coordinates are send to the server but the service which took the coordinate using gps and mobile network get killed after some time in power balanced mode and power saver mode..... but it doesn't killed in the the performance mode.... that's why i asked this question – Avid khan Jul 11 '17 at 05:50
-
@ ADM i am also done the start the service like START_STICKY and start foreground and also override the onDestroy() and onTaskRemoved() method to check the service is running or not if service killed then they start the service – Avid khan Jul 11 '17 at 05:53
-
Power saver mode handled by Os and main targets are Background network access,Services, and Alarms , So Seems like only thing you can receive are push notification or VOIP push(I am not sure about it) find a way around it. And if you are testing in Xiomi , Oppo and some custom android phone Then you also need to Look for auto-Start permission [see here](https://stackoverflow.com/questions/34149198/how-to-enable-auto-start-for-my-app-in-xiaomi-programmatically). – ADM Jul 11 '17 at 08:26
-
Good luck for that . Post your solution here if you find any work around for this. And that auto-start option is a real pain for me too. – ADM Jul 11 '17 at 09:29
-
Isn't this power saving mode pretty primitive? When would the user ever want a running, streaming app to close its stream automatically? Never, is my suggestion. Prior to stopping an app, opsys should clearly investigate whether the app is active, e.g. on the network. In consequence, you need to run the device with screen on. Worse than anything. I am one huge question mark. – carl Jun 29 '19 at 20:40