Search code examples
androidservicebattery

How can I start service on start up in android? + need some other advice


I'm building an app that collects info about the battery (using background service). I want this service to start running from the moment I turn on the phone, How do I do it?

On the other hand I want to activate the GUI (interface) of the app only when the user clicks on the app. The app and the background service are in the same project.

Is this the correct way to do what I want?


Solution

  • That is the correct way to do it: see https://web.archive.org/web/20210122071943/http://www.tutorialforandroid.com/2009/07/permissions-journey-receivebootcomplete.html for info about listening for the BOOT_COMPLETED Intent. You can start your Service in the BroadcastReceiver and then bind to it in your Activity.