I have built an android app for collecting mobile and wearable sensor data. I want this app to be running in background 24/7 without being killed by OS. I am aware of all the pro and cons of running it 24/7 but that's my main business requirement.
EDIT: I have made it as foreground service and it works as long as I keep interacting with my phone but if I keep it idle for let's say 4-5 hrs OS kill it despite being listed as foreground service
runing a background service after android marshmallow is a headache.
every background operation is suspended by Doze and StandBy Modes.
and even if you use job dispatcher or WorkManger the Minimum interval to run operation is 15 mins even though you set the minimun interval less than 15 mins.
So you need to start a foreground service with sticky notification to do you work. you can take a look on this article to Start working with foreground services.
don't forget to put this premission into manifest file if your app will run on androi Pie
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
and you can rerun you service on phone restart by using a broadcast receiver which listen to this action
<action android:name="android.intent.action.BOOT_COMPLETED" />
and also you can stop it by listening to this action
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With