Android Intercept Recent Apps Button

How to detect Recent Apps system button clicks (Honeycomb+)

None of standard Activity Lifecycle methods is called when "Recent Apps" button pressed. Activity will stay active after list of recent apps popups. Through semi-transparent left part of this list you can even observe application animation is still running, if you running a game with some animation that didn't handle this situation properly. Actually many of games in Google Play didn't handle this situation properly, even good ones, like Angry Birds.

The only Activity method are getting called when user opens "Recent Apps" list (or returns from it) is onWindowFocusChanged with boolean parameter hasFocus. When user open list of Recent App method onWindowFocusChanged() called with hasFocus equals false, and same method called with hasFocus equals true when user pressing Back in this list.

Recent apps button in android

Is that possible to override recent apps button in android?

Not from an ordinary SDK app.

You are welcome to build your own custom ROM that modifies the overview screen, then convince people to install your custom ROM on their devices.

Opening recent apps on button click

ActivityManager has method getrunningtasks() .

ActivityManager activity_manager = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);

then call the getRunningtasks() to get a list of the current Running tasks :

List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

for (int i = 0; i < recentTasks.size(); i++) {
Log.d("Executed app",
"Application executed : "
+ recentTasks.get(i).baseActivity.toShortString()
+ "\t\t ID: " + recentTasks.get(i).id + "");
}

and please add the permission to get the running tasks in your manifest file like the following :

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

Hope that helps .

Disable recent tasks button on Android 5.0

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" />

Android: Control action to happen if user closes app with Recent Apps Button

Update user online status in onPause().

onPause() use-case as per Docs.

This callback is mostly used for saving any persistent state the
activity is editing, to present a "edit in place" model to the user
and making sure nothing is lost if there are not enough resources to
start the new activity without first killing this one. This is also a
good place to stop things that consume a noticeable amount of CPU in
order to make the switch to the next activity as fast as possible.



Related Topics



Leave a reply



Submit