android 监听当前页返回键回到桌面,再次点击app回到当前页

来源:互联网 发布:ubuntu jdk aptget 编辑:程序博客网 时间:2024/04/29 01:42
@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {    switch(keyCode){        case KeyEvent.KEYCODE_BACK:            Intent home = new Intent(Intent.ACTION_MAIN);            home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);            home.addCategory(Intent.CATEGORY_HOME);            startActivity(home);            return true;    }    return super.onKeyDown(keyCode, event);}
 FLAG_ACTIVITY_NEW_TASK

If set, this activity will become the start of a new task on this history stack.

ACTION_MAIN

Added in API level 1
String ACTION_MAIN

Activity Action: Start as a main entry point, does not expect to receive data.


CATEGORY_HOME

This is the home activity, that is the first activity that is displayed when the device boots.



0 0