onCreate flow continues after finish() onCreate flow continues after finish() android android

onCreate flow continues after finish()


I'm guessing that it is because finish() doesn't cause the onCreate method to return. You could try simply adding

finish();return;

Or use an if else

@Overridepublic void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.layoutb);  if(good data){      //do stuff  }else{      finish();  }}


It seems like finish() does not work until onCreate() return control to system. Please refer to this post: about finish() in android. You have to consider this issue if you don't want any of your code to be executed after calling finish.

Hope it helps.