標籤:des android style blog http color io os ar
在android2.2以後,如果服務在ondestroy裡加上了start自己,用kill backgroudprocess通常無法結束自己。有一種最新發現的方法,利用反射調用forceStopPackage來結束進程Method forceStopPackage = am.getClass().getDeclaredMethod("forceStopPackage", String.class);forceStopPackage.setAccessible(true);forceStopPackage.invoke(am, yourpkgname); 需要在manifest裡加上shareduid定義android:sharedUserId="android.uid.system" 另外加上許可權<uses-permission android:name="android.permission.FORCE_STOP_PACKAGES"></uses-permission> 並且採用系統platform簽名因為需要用FORCE_STOP_PACKAGES許可權,該許可權只賦予系統簽名級程式即可實現強制停止指定程式還有一種方法 利用linux的kill -9命令我也是網上看的,具體行不行,你試試吧
參考資料: http://blog.csdn.net/Zengyangtech/article/details/5733631
//結束整個應用進程
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
manager.killBackgroundProcesses(getPackageName());
Android怎麼結束一個進程,我試了用 ActivityManager.killBackgroundProcesses方法去結束,但是沒有反應