0

Possible Duplicate:
Disable back button in android

in my app to from one activity to other just like A->B->C or C->A i have placed buttons because the operations of the app are like that. So there is no need for the default back button of android. If the user wrongly clicks there should not be any operation done. For this how to disable the back button.

Community
  • 1
  • 1
Siva K
  • 4,968
  • 14
  • 82
  • 161

2 Answers2

1

I don't think that you should disable the back button for users. They would probably get angry/upset. I would at least be that.

It's better to either start the activity with FLAG_ACTIVITY_NO_HISTORY or FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS.

Intent intent = new Intent(this, YourActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
Kaj
  • 10,862
  • 2
  • 33
  • 27
1

If you don't want to return to a specific Activity, another approach would be to call finish() after startActivity() from Activity B.

Code snippet:

  Intent i = new Intent(this, C.class);
  startActivity(i);
  finish();
Rohit Singh
  • 16,950
  • 7
  • 90
  • 88
Geoff
  • 773
  • 1
  • 6
  • 13