Dpk
Dpk

Reputation: 199

Disable recent tasks button on Android 5.0

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.

Upvotes: 2

Views: 7905

Answers (2)

Dpk
Dpk

Reputation: 199

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 to add this permission...

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

Upvotes: 11

Chandrakanth
Chandrakanth

Reputation: 3831

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.

Upvotes: 1

Related Questions