I want if click on press back button, checking if previous exists
I dont use put extra
public void onBackPressed() {
super.onBackPressed();
if (//Have activity){
// Go to home
} else {
// Go to register
}
}
I want if click on press back button, checking if previous exists
I dont use put extra
public void onBackPressed() {
super.onBackPressed();
if (//Have activity){
// Go to home
} else {
// Go to register
}
}
You can check this method:
if (!isTaskRoot()) {
super.onBackPressed();//or finish()
} else {
Intent intent = new Intent(Main2Activity.this, MainActivity.class);
startActivity(intent);
finish();
}
// isTaskRoot() returns 'true' if this is the root activity, else 'false'.
/* If it returns 'true' this means the current activity is the root activity of your
application right now & no activity exist on the back stack, if you press back at
this moment your app will be closed. But now you can handle the back press by checking
is the current activity a root activity or not like below */
if(isTaskRoot()) {
// Start an activity or do whatever you want
} else {
super.onBackPressed();
}