i have a remote service. I have a mainactivity that binds onresume and unbinds onpause. The service sends broadcasts like onstart oncreate and so on for the activity.
For some reason my service gets restarted so it goes oncreate onstartcommand(no ondestroy) like 4 times in say a min and then all of a sudden it just settles down and runs for ever.
I put try catches around everything and nothing. i added a log.d onlowmemory aswell and nothing.
But here is the strange part it only happens when i have my phone plugged in(debugging).
System can kill any service or activity if only there is need for that. There are two things you can do:
Keep low – make sure, that your service use as small amount of memory and CPU as possible.
Tag your service as foreground – look into documentation for example how to do that. It don’t ensure that your service will not be killed, but rather shift it a bit in the line, so #1 advice is still actual.