I’ve been working with Android for just a couple of weeks now and have some troubles with Services.
I have a background service running which checks every minute or so if a scheduled action needs to be executed. Second use is to store some user data and make them available for my activities. There are two issues:
- The service gets binded by my main application but it seems that once I quit the main app, the service gets destroyed too. Why is that and what can I do against it?
- The service doesn’t run forever but seems to get stopped at a random point.
I understand why Android kills my service and so on and I also tried to use the AlarmManager instead of using a Timer in the service. These approaches somehow work, but they are just not versatile and dynamic enough.
So how can I have both an regular schedule check and some kind of data-sharing the right Android-like way?
You need to read about
local service
and remote service
You can use following link to see difference or goto http://developer.android.com/guide/topics/fundamentals.html link to read about fundamental component of android.
http://saigeethamn.blogspot.com/2009/09/android-developer-tutorial-for_04.html
http://saigeethamn.blogspot.com/2009/09/android-developer-tutorial-part-9.html
You can run a thread using TimerTask and Timer to schedule your task at regular interval
I was using following code to show result on UI.