0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Asad Rao
  • 3,190
  • 1
  • 22
  • 26
  • Put a break statement after your finish() call. – rf43 Jul 19 '11 at 16:24
  • possible duplicate of [Calling finish() on an Android activity doesn't actually finish](http://stackoverflow.com/questions/4924071/calling-finish-on-an-android-activity-doesnt-actually-finish) – Kaarel Jul 19 '11 at 16:42

3 Answers3

2

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.

Wroclai
  • 26,835
  • 7
  • 76
  • 67
  • but sir my situation is that these lines are exist method within a method, and in parent method are calling 25 places, where different code exist(or some other exist which i want not execute but in your suggestion when method call complete, that line execute), I Simply want I complete exit from this activity, neither a single line execute after that. – Asad Rao Jul 22 '11 at 16:26
  • 1
    Elaborate your code. From what you've wrote in the comment above your code isn't properly designed. – Wroclai Jul 23 '11 at 10:40
0

this.finish();
return;

Matt
  • 5,461
  • 7
  • 36
  • 43
  • but sir my situation is that these lines are exist method within a method, and in parent method are calling 25 places, where different code exist(or some other exist which i want not execute but in your suggestion when method call complete, that line execute), I Simply want I complete exit from this activity, neither a single line execute after that – Asad Rao Jul 22 '11 at 16:29
0

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

Zwiebel
  • 1,605
  • 4
  • 21
  • 37
  • but return statement only return from this method and code after that method call will execute. i will not execute any single line after that. – Asad Rao Aug 30 '12 at 13:58