I'm using some services like Google Maps
and Text To Speech
and when I close my app, those same processes are running in the background even after my Android app is closed.
What can I do to make sure that my processes are finished when my app is not in the foreground?
One way to do this will be like this
If you have a homescreen or any screen where you will be killing all activities/components, override the onDestroy
and call stopService
method
@Override
protected void onDestroy() {
super.onDestroy();
stopService(new Intent(this, AppLocationService.class));
}
In this case my app will be running service named AppLocationService
If you want kill service process forcefully, you can use following code:
Process.killProcess(Process.myPid());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.