Skip to content Skip to sidebar Skip to footer

Android Service Fails To Connect To Server When The Activities Are In The Background

this is my first post on stackoverflow so I hope I am doing everything correctly. I am developing my first android App and I am experiencing weird behavior on some devices. I have

Solution 1:

It may be related some kind of "Battery optimization" which could prevent background apps from accessing the network -- see, for example, https://www.reddit.com/r/Xiaomi/comments/4r6eld/does_battery_optimization_ever_work_for/

after i had some problems with background apps on MIUI, i figured it hat something to do with the battery saver feature in MIUI. When i just set "Manage apps' battery usage" to standard, the background apps rarely work, even if they have autorun permission. "Rarely work" means: Google Inbox does not sync, Google Maps does not track, some location based apps (like Rain Alarm) do not show rain notifications, and so on.

I had to set EVERY of these apps to the exception list, so that the battery optimization does not affect them. [...]

So, it may be that Xiaomi users (and users whose devices have similar functionality) need to manually add your app to a whitelist.

I don't know if "optimization" settings like these are on by default -- I would certainly hope they aren't.

Solution 2:

Check following permission added in manifest file

<uses-permissionandroid:name="android.permission.INTERNET" /><uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE"/>

Post a Comment for "Android Service Fails To Connect To Server When The Activities Are In The Background"