久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

Android 結(jié)束進(jìn)程的方法

 techres 2012-02-04

void android.app.ActivityManager.restartPackage(String packageName)

public void restartPackage (String packageName)

Since: API Level 3

Have the system perform a force stop of everything associated with the given application package. All processes that share its uid will be killed, all services it has running stopped, all activities removed, etc. In addition, a ACTION_PACKAGE_RESTARTED broadcast will be sent, so that any of its registered alarms can be stopped, notifications removed, etc.

You must hold the permission RESTART_PACKAGES to be able to call this method.

Parameters

packageName

The name of the package to be stopped.

 

 

使用這個(gè)類的具體源代碼

Java代碼 

  1. final ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);    
  2. am.restartPackage(getPackageName());    
 

再加上uses-permission

 

 

Xml代碼 

  1. <uses-permission android:name="android.permission.RESTART_PACKAGES"></uses-permission>   
 

 

 

結(jié)束進(jìn)程還有android.os.Process.killProcess(pid)只能終止本程序的進(jìn)程,無法終止其它的

 

public static final void killProcess (int pid)

Kill the process with the given PID. Note that, though this API allows us to request to kill any process based on its PID, the kernel will still impose standard restrictions on which PIDs you are actually able to kill. Typically this means only the process running the caller's packages/application and any additional processes created by that app; packages sharing a common UID will also be able to kill each other's processes.

 

public void finish ()

Call this when your activity is done and should be closed. The ActivityResult is propagated back to whoever launched you via onActivityResult().

這是結(jié)束當(dāng)前activity的方法

 

 

在android2.2版本之后則不能再使用restartPackage()方法,而應(yīng)該使用killBackgroundProcesses()方法 

manager.killBackgroundProcesses(getPackageName()); 

 

  1. ActivityManager manager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);       
  2. manager.killBackgroundProcesses(getPackageName());    
 

加入權(quán)限

  1. //需要在xml中加入權(quán)限聲明    
  2. <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>  
 

 


 

另外,,在android2.2以后,,如果服務(wù)在ondestroy里加上了start自己,,用kill backgroudprocess通常無法結(jié)束自己,。

 

還有一種最新發(fā)現(xiàn)的方法,,利用反射調(diào)用forceStopPackage來結(jié)束進(jìn)程

 

代碼如下

 

  1. Method forceStopPackage = am.getClass().getDeclaredMethod("forceStopPackage", String.class);  
  2. forceStopPackage.setAccessible(true);  
  3. forceStopPackage.invoke(am, yourpkgname);  
 

 

需要在manifest里加上shareduid定義

  1. android:sharedUserId="android.uid.system"  
 

 

另外加上權(quán)限

  1. <uses-permission android:name="android.permission.FORCE_STOP_PACKAGES"></uses-permission>  
  2.    
 

 

并且采用系統(tǒng)platform簽名


因?yàn)樾枰肍ORCE_STOP_PACKAGES權(quán)限,,該權(quán)限只賦予系統(tǒng)簽名級程序

 

即可實(shí)現(xiàn)強(qiáng)制停止指定程序

 

還有一種方法 利用linux的kill -9命令

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多