onBackPressed删除@Override注释

时间:2011-12-28 07:03:34

标签: android

我在我的应用程序中使用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库。

这是因为图书馆还是什么?

1 个答案:

答案 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); 
}