古詩詞大全網 - 漢語詞典 - android中如何殺死自己的進程

android中如何殺死自己的進程

其中的killBackgroundProcesses是android.app.ActivityManager類中的方法,而必須在Manifest.xml文件中加入<uses-permission

android:name="android.permission.KILL_BACKGROUND_PROCESSES"/> 的設置。 restartPackage (String packageName) 也是壹種殺死進程的方法。 該方法的原型 public void killBackgroundProcesses (String packageName) 僅有壹個參數為package Name,使用方法比較簡單。

ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

am.killBackgroundProcesses("cn.com.android123.cwj"); // API Level至少為8才能使用