@Override
public void onBackPressed() { // TODO Auto-generated method stub super.onBackPressed(); Toast.makeText(this, "呵呵哈哈", Toast.LENGTH_LONG).show(); //return ;}
这样,当按回退健时,activity退出,并且提示"呵呵哈哈"!
当注释掉super.onBackPressed()时,按回退健,只提示"呵呵哈哈"!
onBackPressed()在Activity.class里实现:
public void onBackPressed() {
finish(); } super.onBackPressed()是执行系统的默认动作,就是退出当前activity,所以当我们要重写这个函数时,不要加super.onBackPressed(),就可以不退出activity,执行自己的代码啦~
来自:http://www.2cto.com/kf/201304/204021.html