1

If we call the acitivty.finish() and there are some lines of code below that. will that be executed once the finish() has been called? or ignored?

1 Answers1

7

If we call the acitivty.finish() and there are some lines of code below that. will that be executed once the finish() has been called?

Yes Because acitivty.finish() is not an abort

CHECK this Example

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.e("TEST", "BEFORE FINISH");
        finish();
        Log.e("TEST", "AFTER FINISH");
        Log.e("TEST", "AFTER FINISH");

    }

RESULT

enter image description here

Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • But if i use intent before finish and add this lines after finish.. will it work? – Vidhi Dave Apr 10 '18 at 06:14
  • 1
    @VishvaDave After calling finish() your activity will not be immediately finished but only planned to be 'finished'. So execution of code will continue – AskNilesh Apr 10 '18 at 06:16