Reputation: 1945
I understand that when you call an Intent
to start a service, the service continues until it is explicitly ended.
I would like the service to persist multiple activities. How do I end it when all activities of the application is destroyed?
Or does it get destroyed automatically?
Upvotes: 1
Views: 470
Reputation: 9996
In the main Activity
, override onDestroy
and call stopService
@Override
public void onDestroy()
{
super.onDestroy();
Toast.makeText(<Context>, "Stopping service", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(<MainActivity>.this, <YourService>.class);
stopService(intent);
}
Upvotes: 2