简体   繁体   中英

How to completely finish my activity, and after activity.finish no further code will execute?

I want to completely finish my activity, and after activity.finish no further code will execute?

Example:

Intent scoringOpponentTeam = new Intent(this,TestActivitySecond.class);
startActivity(scoringOpponentTeam);
this.finish();
Log.i("after Finish Called", "after Finish Called--------"+"after Finish Called");

In above example, I want that no Log.i() line will execute.

When you are calling finish() , Android will let your code in the specific block after the finish() call execute, and that is why the log message appears. A simple return statement after the finish() call is the solution.

However, there is no need for you to explicity "kill" your Activity since Android handles this perfectly on its own.

this.finish();
return;

You need a return statement after your this.finish();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM