2013-02-05 66 views
0

我有實現與多個屏幕的應用程序,從屏幕的任何退出使用android:noHistory="true" ...我有EXITButton在我的應用程序中的所有屏幕..後退按鈕:noHistory =「真」

但在處理應用程序,如果用戶點擊BACKButton應用程序結束我都面臨着一個問題,在表...

Default Tablet Buttton in TABLET

現在我正在尋找一個AlertDialog,而用戶點擊默認返回Button ..

向我建議任何解決方案的問題。

一些建議後,我想這一點,這也並非任職..

的,我試圖代碼..

@Override 
public void onBackPressed() { 
    // TODO Auto-generated method stub 
    super.onBackPressed(); 
    AlertDialog.Builder builder = new AlertDialog.Builder(Login.this); 
    builder.setMessage("Are you Sure want to close the Application..?") 
      .setCancelable(false) 
      .setTitle("EXIT") 
      .setNegativeButton("No", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        dialog.cancel(); 
       } 
      }) 
      .setPositiveButton("Yes", 
        new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          finish(); 
         } 
        }); 
    AlertDialog alert = builder.create(); 
    alert.show(); 

} 
+1

忽略super.onBackPressed(); – SKT

回答

2

覆蓋onBackPressed活動做任何你想要的(喜歡流行上一個對話框)。

+0

它沒有工作,請查看我編輯的問題請... – MGR

+0

不要調用super.onBackPressed。該功能結束活動。 –

+0

非常感謝,它的工作... – MGR

3

試試這個,

Ovrride onbackpressed你的活動。

@Override 
public void onBackPressed() { 
    super.onBackPressed(); 
    //ADD ALERT DIALOG HERE 

} 
+2

不要叫超級,這將導致它完成活動。只需重寫它。 –

+0

謝謝你的工作... – MGR

+0

感謝您的提示.. – MuraliGanesan