1

I looked through all the posts about it in here and in android documentation about service. I still can't understand how to do it.

I want to write application that collects battery data all the time event when the UI is closed. I found that I need to use a service for this with BindService & StrartService so the UI Activity could communicate with the service and the service could also run by it self in case the UI activity closes.

The thing that I can't understand is how do I make the service run "forerver" even when I close it with android app manager. For example: Whatsapp application even if I close it with the app manager in the moment that someone sends me a message I still get it and whatsapp turns on.

Do I need to use thread (runnable interface with run function) or what?

Alex K
  • 5,092
  • 15
  • 50
  • 77

1 Answers1

2

You may try to override onStartCommand() in your service and return START_STICKY; to let the system know your service should run until it terminates itself.

lenik
  • 23,228
  • 4
  • 34
  • 43
  • @AlexKapustian first of all you need to extends from IntentService not Service, onStartCommand is a method from IntenService and onBind From Service. – BlaShadow Jan 22 '13 at 02:23