I think this question is asked many time in stackoverflow
but still so many people struggling to resolved it.
In my android app I have to wake up device
In my android app I have to wake up device for every 15 min to getting current location and send it to server.
I have tested it on Xiaomi Mi 5s (Android 6.0.1). When I close the application, the application goes to sleep :( AlarmManager
with setExactAndAllowWhileIdle()
not working ¯\_(ツ)_/¯
Yes, it's working fine in almost all standard/popular devices like Samsung, LG (Nexus 5X), Sony, Motorola, Pixel...
MY SOLUTION:
The manifest entry for each type of component element — <activity>
, <service>
, <receiver>
, and <provider>
— supports an android:process
attribute that can specify a process in which that component should run.
You need add this string android:process=":service"
in your AndroidManifest.xml
Like this:
...
<receiver
android:name="your.full.packagename.MyWakefulReceiver"
android:process=":service"
android:enabled="true"/>
<service
android:name="your.full.packagename.MyLocationService"
android:process=":service"/>
<service
android:name="your.full.packagename.MySendService"
android:process=":service"
android:exported="false" />
...
I have tested this solution on Xiaomi Mi 5s. It's work !!!
IMHO it seems that the Xiaomi firmware kills the main process whenever the user exits the application...
Probably these Chinese phones have disabled app wake for receiving alarm events to conserve battery life. I know that some Chinese makers don't wake app to receive push notifications if they are closed for battery conservation earlier. Thus until the app is manually opened again, it will not be woken up by the OS for any event processing.
However this behaviour can be changed. Check power management settings and change accordingly to allow apps to be woken up at regular intervals or when needed. I think it could be Restricted Mode or something similar.
Hi I have got same issue while testing in Xiomi phone.leeco I haven't much idea. Xiomi phone have their own OS that is MIUI.When we cleared RAM it clear all the apps execpt some of apps register in OS. Like Whatsapp and facebook some other famous apps.
I have tried Service, Alarm Manager and Scheduler but not get any success.
They provide some manually specfic way to run services.I have checked Leeco it used Android OS.
Solution for MIUI 7.0 => Security => Autostart => select Apps that you want to run in background => Reboot After reboot your device should able to run your application services in background like other android devices do.
MIUI 4.0 settings
MIUI AutoStart Detailed Description
According to me you can try with Services then check if it work or not.
Thanks hopefully you'll get bit help from this.
I agree with you. But I think you should try with JobScheduler once. You will find official documentation https://developer.android.com/reference/android/app/job/JobScheduler.html Best example I find https://github.com/googlesamples/android-JobScheduler I don't have test it.according to me you have to try this.
EDIT
If you want to run your application in doze mode in 6.0 or later, you have to white list your application check out
https://www.bignerdranch.com/blog/diving-into-doze-mode-for-developers/
https://developer.android.com/training/monitoring-device-state/doze-standby.html
Imtiyaz