欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android?殺死進(jìn)程幾種方法詳細(xì)介紹

 更新時(shí)間:2022年10月14日 16:14:57   作者:wuyudong  
這篇文章主要介紹了Android?殺死進(jìn)程的相關(guān)資料,并整理了幾種實(shí)現(xiàn)方法,及具體實(shí)現(xiàn)的代碼,需要的朋友可以參考下

Android 殺死進(jìn)程:

             對于進(jìn)程結(jié)束在開發(fā)APP應(yīng)用當(dāng)中還是有必要的,這里整理了三種方法,大家可以根據(jù)需求選用。

當(dāng)應(yīng)用不再使用時(shí),通常需要關(guān)閉應(yīng)用,可以使用以下三種方法關(guān)閉android應(yīng)用:

第一種方法:首先獲取當(dāng)前進(jìn)程的id,然后殺死該進(jìn)程。

android.os.Process.killProcess(android.os.Process.myPid())

接下來實(shí)踐一下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" >

  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:onClick="click"
    android:text="自殺" />

</RelativeLayout>

添加點(diǎn)擊事件代碼  

 public void click(View view) {
    // 獲取當(dāng)前進(jìn)程的id
    int pid = android.os.Process.myPid();
    // 這個(gè)方法只能用于自殺操作
    android.os.Process.killProcess(pid);

  }

在點(diǎn)擊按鈕之前,可以看到進(jìn)程

點(diǎn)擊按鈕后,進(jìn)程消滅

第二種方法:終止當(dāng)前正在運(yùn)行的Java虛擬機(jī),導(dǎo)致程序終止

System.exit(0);

android.permission.KILL_BACKGROUND_PROCESSES

第三種方法:強(qiáng)制關(guān)閉與該包有關(guān)聯(lián)的一切執(zhí)行

ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); 
manager.restartPackage(getPackageName());
<uses-permission android:name="android.permission.RESTART_PACKAGES" />

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論