Issue
How to handle a back button in an activity? I have some buttons. If I click one of the buttons, it's redirecting to the buttons which I required. It's working fine but when I press back button it gets finished.
How to solve this problem? I have only one activity for all those buttons.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK))
{
return false; //I have tried here true also
}
return super.onKeyDown(keyCode, event);
}
I have used above code to handle back button but it's not working. When I press back button its struck there itself.
Solution
You can handle it like this:
for API level 5 and greater
@Override
public void onBackPressed() {
// your code.
}
older than API 5
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// your code
return true;
}
return super.onKeyDown(keyCode, event);
}
Answered By - Saurabh Pareek
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.