I want to disable back button in my application. And if not possible, then I want to open MainActivity when click on it. Is there any solution? If yes help me?
Asked
Active
Viewed 6,084 times
3 Answers
2
simply write these lines
@Override
public void onBackPressed() {
}

AMAN SINGH
- 3,491
- 6
- 28
- 44
-
1this is not working – Dinesh Sheoran Apr 03 '17 at 13:09
-
show me your code. how's this possible. is it Activity class? – AMAN SINGH Apr 03 '17 at 13:11
2
You can simply use this if you want to disable completely back button:
@Override
public void onBackPressed() {
moveTaskToBack(false);
}

Johny
- 625
- 2
- 6
- 26
0
you can use this code for onback button click to intent another activity.
@Override
public void onBackPressed() {
Intent intent=new Intent(Caly_act.this,MainActivity_tab.class);
startActivity(intent);
finish();
}

Hasmukh Kachhatiya
- 478
- 4
- 14