reiley reiley - 1 year ago 58
Android Question

Go to home screen instead of previous Activity

I know this question has been asked many times before, but any of the solution is not working and my situation is a little bit different.

I've an

which can be called from many different Activities. But I want when the user presses back button, instead of previous activity, app should go to Home screen.

One way to use
but then I'll have to use it in every calling Activity.

Answer Source

you can override onBackPressed method as follows. It should work.

 public void onBackPressed() {
     Intent startMain = new Intent(Intent.ACTION_MAIN);