memory - How to kill currently running task in android Marshmallow -
i'm trying find way how kill task in android marshmallow have 2 methods both works fine in android 4.0.3 , android 5.0.1 when trying in android 6.0.1 doesn't work idea resolve problem !,
list<applicationinfo> packages; packagemanager pm; pm = getpackagemanager(); //get list of installed apps. packages = pm.getinstalledapplications(0); activitymanager mactivitymanager = (activitymanager)getapplicationcontext().getsystemservice(context.activity_service); string mypackage = getapplicationcontext().getpackagename(); (applicationinfo packageinfo : packages) { if((packageinfo.flags & applicationinfo.flag_system)==1)continue; if(packageinfo.packagename.equals(mypackage)) continue; mactivitymanager.killbackgroundprocesses(packageinfo.packagename); }
and method :
activitymanager = (activitymanager) getapplicationcontext().getsystemservice(context.activity_service); (activitymanager.runningappprocessinfo pid : am.getrunningappprocesses()) { am.killbackgroundprocesses(pid.processname); }
try using in second method.
android.os.process.killprocess(pid);
kill process given pid. note that, though api allows request kill process based on pid, kernel still impose standard restrictions on pids able kill. typically means process running caller's packages/application , additional processes created app; packages sharing common uid able kill each other's processes. taken here
i recommend getting application id using
android.os.process.mypid();
Comments
Post a Comment