I would like to finish an activity from inside the onCreate method. When I call finish(), onDestroy() is not immediately called, the c
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
@Override
public 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.