2010-04-12 51 views

回答

0

您可以覆蓋活動的方法的onkeydown:

public boolean onKeyDown(int keyCode, KeyEvent event) { 
     if(keyCode == KeyEvent.KEYCODE_BACK){ 
      //Show the dialog and get the response 
     } 

//Do a if here with your variable returned from the dialog  
return super.onKeyDown(keyCode, event); 
    } 
+0

謝謝,這正是我想要的。 – backspace7 2010-04-13 01:58:28

0

你試過重寫onPause()嗎?

在我的情況下,當我點擊後退按鈕時,它在調用onStop()之前首先調用onPause()。

這是一個很好的視頻說明的應用生命週期突未:

http://blip.tv/file/958450/

+0

感謝重播。 是的,我試過onPause(),但失敗了。 我必須展示一種模態對話框,但我不知道該怎麼做。 – backspace7 2010-04-12 08:13:36

+0

如果沒有,你有一個方法onBackPressed(),可以讓你做任何你想要的東西,當後退按鈕被按下。 所以你重載這個功能,並在你實現你的模態對話框。 – Spredzy 2010-04-12 08:16:20

+0

其實,我想鉤住一個後退鍵,使活動變爲背景()。 – backspace7 2010-04-12 08:25:13

相關問題