There are many threads with similar issues and recommendations to fix. I've tried all and none works for my case except putting the service in foreground, which I do not want to do so far.
I cannot post a comment to existing threads as I don't have enough reputations and I want to question, so can't answer. This is the only choice to bring my question and look for some expert's opinions and recommendations.
Existing threads with similar issues discussed,
Time taken for Android Service to restart after being forcibly killed
Background Service getting killed in android
Android: Scheduling restart of crashed service with HUGE delay?
MY PROBLEM:
I've a service that starts at boot time (listening to intent BOOT_COMPLETED
)
I start a thread that does interaction with other service through a socket and is interrupted when the service is killed (onDestroy)
.
Using Wifi on phone, my service is never killed by android and it works as expected.
If I switch to 3G only (At&T SIM), My service gets killed approx. after 1800 seconds (30 minutes) and scheduled to be restarted in approx. 3600 sec (1 hour). All this time the thread that service started is doing SQLLite calls and interacting with this other service.
Android thinks my service has been idle for 1800+ seconds and will kill its with long restart time.
Questions:
What do I need to do to tell Android ActivityManager that my service is doing work using a thread it spun, so it should not be killed. Happens only on 3G.
How to reduce the timer to under 20 seconds. 1 hour is just too long. I did used AsyncTask to spin other thread that loops for ever sleeping 1 second, but still my service gets killed.
How Android behavior changes when using 3G versus Wifi in determining which service to kill?