2014-10-09 111 views
-1

我想要捕獲某些活動中的後退按鈕,以詢問用戶是否要保存表單數據。這可能嗎?Android捕獲後退按鈕

我需要類似的信息(僞):

onBackButtonPressed{ 
    AlertDialog("Do you want to save?") 
    if (OkPressed) { 
     // do the saving 
    }else{ 
     // Continue with the backButton action 
    } 
} 

任何幫助,將不勝感激

謝謝

+0

爲什麼不自動爲用戶保存數據? – michaelcarrano 2014-10-09 01:35:07

+0

naXa - 感謝您的鏈接,當我尋找解決方案時,我似乎沒有找到該問題+答案。謝謝。我在那裏找到的解決方案。讓你的評論成爲答案,我會接受它 – user1137313 2014-10-09 04:49:50

回答

0

覆蓋onBackPressed()您的活動

public void onBackPressed(){ 
    AlertDialog("Do you want to save?") 
    if (OkPressed) { 
     // do the saving 
    }else{ 
     // Continue with the backButton action 
    } 
}