I have Android service to run and send email every 9 mins but after some cycles it quits. this app is also installed in my Android froyo but it works good for more than 2months now.. I can see the logs in logcat that the service quits but my problem is I cannot understand what does it mean.. Can someone help me with this? Thanks!! any help would be appreciated…
here is my source code:
https://gist.github.com/77a40ac93cd311acb56c
Logcat logs:
The point behind using
AlarmManageris so that your service only needs to be in memory when it is doing actual work, and can go away in betweenAlarmManagerevents. You have managed to not do that, and therefore your code will not work reliably.If you want to “send email every 9 mins”, you should:
Move the
BroadcastReceiverto be a public Java class, registered in the manifest via a<receiver>element, and remove theregisterReceiver()/unregisterReceiver()stuff.Switch your service to be an
IntentService, so you get a background thread (which you need for your work, but your current code lacks) and so the service can automatically shut down when there is no more work to be done.Add in the logic for the
WakeLockthat you will need since you are using a_WAKEUP-style alarm. You could combine this and the previous steps by switching to myWakefulIntentService, if you wish.Deal with the case where the user reboots the device, if you want your alarms to continue after the reboot, such as by scheduling them again via an
ACTION_BOOT_COMPLETEDBroadcastReceiver.