Shirish Herwade
Shirish Herwade

Reputation: 11711

how to make another activity behave like home activity(first app launching actvity)

I have 4 activities in my application. I want back button to work normally on first three activities(i.e. going to previous screen on back button press); except the last.

I want that, when I press back button on fourth activity(screen), user should go to second Activity(Second screen). But the contents on that Activity should be same when user went from second screen to third screen.

And after that, when I press back button now on this second screen, I should exit application normally i.e. no system.exit() etc, rather like normally a application exists after back button press on first screen or first activity.

Upvotes: 0

Views: 354

Answers (2)

Bhaskar
Bhaskar

Reputation: 537

for third activity do this in manifest file: android:noHistory="true"

and do this in fourth activity:

Button backButton = (Button)this.findViewById(R.id.back);
backButton.setOnClickListener(new OnClickListener() {
  @Override
  public void onClick(View v) {
    finish();
  }
});

Upvotes: 1

Vamshi
Vamshi

Reputation: 1495

Try this:

Intent intent = new Intent(this, Abc.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

Upvotes: 0

Related Questions