亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android9 清除最近進程列表實現(xiàn)方法

 更新時間:2023年06月12日 10:08:44   作者:vivian310  
這篇文章主要為大家介紹了Android9 清除最近進程列表實現(xiàn)方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

項目需求

最近項目中有一個需求,需要清除Recent tasks列表中的所有task,相當于點擊最近-全部清除的動作。

具體實現(xiàn)如下

1、添加權限

在AndroidManifest.xml文件中添加以下權限

<!--應用必須是系統(tǒng)APP,并且sharedUserId為system-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.test"
    android:sharedUserId="android.uid.system">
<!--添加權限-->
 <uses-permission android:name="android.permission.REAL_GET_TASKS"/>

2、代碼實現(xiàn)

public static void removeAllRecentTasks(){
    try {
            List<ActivityManager.RecentTaskInfo> recents = ActivityManagerWrapper.getInstance()
                    .getRecentTasks(Integer.MAX_VALUE, ActivityManager.LOCK_TASK_MODE_NONE);
            for( int i = 0; i < recents.size(); i++ ) {
                ActivityManagerWrapper.getInstance().removeTask(recents.get(i).persistentId);
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG,"Remove recent tasks, Exception: " + e.toString());
        }
    }
}

以上就是Android9 清除最近進程列表實現(xiàn)方法的詳細內(nèi)容,更多關于Android清除進程列表的資料請關注腳本之家其它相關文章!

相關文章

最新評論