Is it possible to stop all started services when the user hits the Home Button?
I use:
startService(new Intent(ClassName.this, Class
Is it possible to stop all started services when the user hits the Home Button?
Not directly. For starters, you have no way of knowing they pressed HOME.
If you only want the service running while activities are using it, consider getting rid of startService()
. Instead, use bindService()
in the onStart()
methods of the activities that need the service, and call unbindService()
in their corresponding onStop()
methods. You can use BIND_AUTO_CREATE
to have the service be lazy-started when needed, and Android will automatically stop the service after all connections have been unbound.