Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android service stops working after application is not in use for awhile

I have a service for my application that runs fine, but when a user is not using there phone for while like 20 minutes the service just doesnt work any more. is there something i suppose to be doing like saving a state or something, i am lost at this point. I dont see why the service doest keep running, I look in the application>running services on my phone and it still says its running. Any suggestions?

like image 535
user516883 Avatar asked Feb 19 '11 20:02

user516883


2 Answers

I faced the same problem few time back. Then I started to use Android Alarm Service. That solved my problem. Here is a reference link http://android-er.blogspot.com/2010/10/simple-example-of-alarm-service-using.html

like image 63
Rohit Mandiwal Avatar answered Sep 27 '22 19:09

Rohit Mandiwal


If you want to keep running in the background (e.g. downloading something), you need to grab a wakelock (http://developer.android.com/reference/android/os/PowerManager.html)

Also, look at the following if you happen to do downloads in the background: http://developer.android.com/reference/android/net/ConnectivityManager.html#getBackgroundDataSetting()

like image 41
Szabolcs Berecz Avatar answered Sep 27 '22 19:09

Szabolcs Berecz