This is my first time experimenting with android services, so I am a little bit lost. I am developing an application that requires a service to run in the background at all time. This service is initialized from an onclick event in the main activity. To start the service I use the following code:
Intent Test = new Intent(this, testService.class);
startService(Test);
In the service I basically have two things. In the method onCreate I initialize a timer and every 30min it opens a new thread and checks if the server has any new data. While on the onStart methods I register a Receiver.
After a couple of hours the service is being killed, is it possible that the garbage collector is removing the service? My suspicion is that the way I am initializing the service it is still binded to the activity “main” process. What can I do to make sure that the service keeps running?
Thanks
You need AlarmManager instead of timer for this task.