簡體   English   中英

在Android中殺死在后台運行的應用程序

[英]Kill the applications running in background in android

我正在嘗試使用我的應用程序終止后台運行的應用程序,但無法終止該進程。

android.os.Process.killProcess(pid);
android.os.Process.sendSignal(pid,
android.os.Process.SIGNAL_KILL);
manager.killBackgroundProcesses(pid);

此處pid是后台運行進程ID。

每個Android應用程序都有自己的用戶ID,組ID,並且大多數時間都是在自己的進程中運行。 因此,您的應用可能沒有殺死其他進程的特權。

顯然存在設計缺陷,您最好陳述一下實際要做什么。

使用以下killBackgroundProcesses:

   try {
            ActivityManager actvityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
            actvityManager.killBackgroundProcesses(pkgn.toString());// pkgn is a process id /////
        } catch (Exception e) {
            e.printStackTrace();
        }

您還必須在清單中添加它

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM