Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill an Android activity when leaving it so that it cannot be accessed from the back button?

Tags:

android

In an given Android activity, I would like to start a new activity for the user at some point. Once they leave the first activity and arrive at the second, the first activity is stale and I want to remove it completely so it can not be accessed again from the back button.

How is the best way to accomplish this? How do I kill or destroy this activity immediately after the user has launched the new activity?

like image 398
JohnRock Avatar asked Mar 31 '10 02:03

JohnRock


People also ask

How can we kill an activity in Android?

15. Activity in Android can be killed using? Answer - D) Activity in Android can be killed using both finishActivity (int requestCode) and finish() method.


1 Answers

You just need to call finish()

Intent intent = new Intent(this, NextActivity.class); startActivity(intent); finish(); 
like image 78
CaseyB Avatar answered Sep 20 '22 03:09

CaseyB