Roman Rdgz
Roman Rdgz

Reputation: 13254

1->2->3 activities, at third "back button" I want to go to the first one

I have a MainActivity, then I call SecondActivity (where I choose a file whose data is given to ThirdActivity.

If back button is pushed, I want the app to go back yo MainActivity and not SecondActivity.

How can I do that?

Upvotes: 0

Views: 859

Answers (3)

Snailer
Snailer

Reputation: 3839

You could also override onKeyPressed() (or whatever it's called) for the back button and startActivity().

Upvotes: 0

DeeV
DeeV

Reputation: 36035

There are two ways to do it.

  1. In SecondActivity, call finish() immediately after you start Activity 3.

  2. Pass in the NO_HISTORY flag in the Intent for SecondActivity when starting it in MainActivity.

Upvotes: 3

David Snabel-Caunt
David Snabel-Caunt

Reputation: 58361

Just after you call startActivity with the Intent for activity 3, call finish in activity 2:

//in activity 2

    Intent intent = new Intent(...);
    startActivity(intent);
    finish();

Upvotes: 1

Related Questions