我在我的应用程序中使用GreenDroid库,我正在尝试捕获/处理后退按钮,这是我的代码:
private Toast toast;
private long lastBackPressTime = 0;
@Override
public void onBackPressed() {
if (this.lastBackPressTime < System.currentTimeMillis() - 4000) {
toast = Toast.makeText(this, "Press back again to close this app", 4000);
toast.show();
this.lastBackPressTime = System.currentTimeMillis();
} else {
if (toast != null) {
toast.cancel();
}
super.onBackPressed();
}
}
我收到此@Override
删除注释问题。如果删除@Override
注释,则super.onBackPressed();
处出现错误,Eclipse说:
对于GDActivity类型,未定义onBackPressed方法。
GDActivity来自GreenDroid库。
这是因为图书馆还是什么?
答案 0 :(得分:0)
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(Build.VERSION.SDK_INT==Build.VERSION_CODES.CUPCAKE) //if it's 1.5
{
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
{ // do something on back.
return true;
}
}
return super.onKeyDown(keyCode, event);
}