2014-10-09 112 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 
    } 
}