I have a service which is a foreground service which runs even when the app is kill. I just wanted to know is there any way I can pause this service when user move to some other activity and resume back when user come back to previous activity.
If you want to kill background services use this .
List<ApplicationInfo> packages;
PackageManager pm;
pm = getPackageManager();
//get a list of installed apps.
packages = pm.getInstalledApplications(0);
ActivityManager mActivityManager = (ActivityManager)getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
String myPackage = getApplicationContext().getPackageName();
for (ApplicationInfo packageInfo : packages) {
if((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM)==1)continue;
if(packageInfo.packageName.equals(myPackage)) continue;
mActivityManager.killBackgroundProcesses(packageInfo.packageName);
}
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.