Issue
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
Solution
It's a pain to run a background service after Android Marshmallow.
Doze and StandBy Modes halt all background operations.
Even if you use job dispatcher or work manager, the minimum interval for running an operation is 15 minutes, even if you set it to less than that.
So you need to start a foreground service with sticky notifications to do your work. You can take a look at this article to learn how to start working with foreground services.
don't forget to put those permissions into your manifest file if your app is targeting android pie
and you can rerun the 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" />
Answered By - Ramzy Hassan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.