Disable recent tasks button on Android 5.0

天大地大妈咪最大 提交于 2020-11-29 11:01:59

问题


I am working on an application that needs to suppress the recent apps button as it is done in the Toddler Lock application. What I want is user should not be able to exit my application by pressing the recent apps button.

In toddler lock (https://play.google.com/store/apps/details?id=marcone.toddlerlock&hl=en) whenever you press the recent apps button the screen flashes a bit but the app return to its own activity. Even if we press the recent apps button multiple times in quick succession and manage to display the recent apps screen after a few milliseconds the app return to its own activity.

I know there must be some service that which is behind the scenes but i cannot exactly figure out.

Can anyone tell me how does the Toddler Lock application manages to suppress the recent apps button. I need to implement exactly same behavior in my application.

I tried the answer that is given on the link below: Altering the result of getRecentTasks

and android intercept recent apps button but these does not work on Android Lollipop.

If there is a way to do this using a home screen in my application please consider that as well.


回答1:


Finally I was able to achieve this by following:

@Override
protected void onPause() {
super.onPause();

ActivityManager activityManager = (ActivityManager) getApplicationContext()
        .getSystemService(Context.ACTIVITY_SERVICE);

activityManager.moveTaskToFront(getTaskId(), 0);

}

will need permission ...

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



回答2:


You have to write a service which will continuously monitor the top activity. If the top activity is from the package com.android.systemui means the user pressed the recent apps button. So at this time you have maintain the top activity from your application and start the same activity again.



来源:https://stackoverflow.com/questions/30497528/disable-recent-tasks-button-on-android-5-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!