How to Detect "Recent Apps" System Button Clicks (Honeycomb+)

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.

What method is ran when user clears Recent Apps in Android

It seems the best way would be to create a Service and look for the onTaskRemoved method to be called.

Look here for extensive conversation: https://android.stackexchange.com/questions/19987/what-actually-happens-when-you-swipe-an-app-out-of-the-recent-apps-list

Here's the Service API I suggest using: http://developer.android.com/reference/android/app/Service.html#onTaskRemoved%28android.content.Intent%29

Detect menu button event

This works for me:

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
return true;
}
return super.onKeyDown(keyCode, event);
}

Return true to prevent this event from being propagated further, or
false to indicate that you have not handled this event and it should
continue to be propagated.

@Override
public boolean onPrepareOptionsMenu (Menu menu) {
return false;
}

Android: Programmatically open Recent Apps dialog

You cannot access that. However, it isn't super hard to roll your own. The getRecentTasks() method returns a list of recently run apps. Simply take the list and add your own UI to it.

One advantage to this is that the default one, at least on older versions of Android, only shows you about 8 apps. If you roll your own can show as many as you want.

How to ignore button click of Recent Activity Button in android 3.0

From peeking into the docs, I think that KeyEvent.KEYCODE_APP_SWITCH is what you're searching for.

You could however also use the KeyEvent.getKeyCode()-method (on the event-parameter) to see which key-code is triggered (and if there is any key triggered), when you press the application switcher.


I played around with this for a while and I have come to the conclusion, that it's not possible.

The KEYCODE_APP_SWITCH-event is not delivered to either onKeyDown() nor dispatchKeyEvent(). Ergo, It can not be handled.

Also, you'll run into problems on Android 4 devices, because the KEYCODE_HOME-event is also no longer dispatched to any of the above methods. See the docs:

Key code constant: Home key. This key is handled by the framework
and is never delivered to applications
.


It also seems that there is no real easy approach to creating a real lock-screen yourself. See this discussion: Developing a custom lock screen

It is well possible to show some custom information on the default lock-screen: Is there a way for me to show a customized message on the lock screen?


For the sake of completeness: In Android L, you'll be able to "lock users in your app", so you don't need to manually override the Hardware keys. Here's the relevant information:

The L Developer Preview introduces a new task locking API that lets
you temporarily restrict users from leaving your app
or being
interrupted by notifications. This could be used, for example, if you
are developing an education app to support high stakes assessment
requirements on Android. Once your app activates this mode, users will
not be able to see notifications, access other apps, or return to the
Home screen, until your app exits the mode.



Related Topics



Leave a reply



Submit