Search code examples
androidbattery

Running in Background


Hi I have simple question I need to run my app in the background when the screen is locked. Using service is the only way? Its seems complicated for my simple program. ( i'm writing simple gps logger which must be logging even if user blocked the phone).


Solution

  • Yes, this is the only way. Use a normal Service, you can also make it sticky to let is restart itself when Android kills it because of low resources.

    Use startService to start is. If you are using bindService it will stop the Service when the Activity is killed. You probably don't want that. Don't forget to call stopService when you don't want to use the Service anymore.

    IntentService is not suitable because it will stop itself when done.