问题
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