Reputation: 1008
Hi i have two activities 1) Login page 2) It shows successfully login, I done perfectly but my problem is i want to open new Login page again after close application at second activity please tell me..
Upvotes: 0
Views: 113
Reputation: 377
I will provide you with the exact and working solution ,this will definitely work.
Create a Activity logout and in that write this code.
Intent intent = new Intent(Logout.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("Exit me", true);
startActivity(intent);
finish();
MainActivity is where you want user to go after logout.
and then in each and every activity write this code.
if( getIntent().getBooleanExtra("Exit me", false)){
finish();
return; // add this to prevent from doing unnecessary stuffs
}
This will Completely Exit your android application and also all the activities will get finished.
Upvotes: 0
Reputation: 6736
Allright you can do it like this:
do this inside your SecondActivity
:
@Override
public void onBackPressed() {
Intent intent = new Intent(SecondActivity.this,FirstActivity.class);
intent.setFlafs(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish(); //finish Second Activity
}
Hope I answered your question.
Upvotes: 1
Reputation: 902
Intent activity= new Intent(FirstActivity.this,SecondActivity.class);
finish(); //This is used to close first activity
startActivity(activity);
Upvotes: 0
Reputation: 5068
you can call finish method when starting successfully login activity. So , when you come back again you will see the login page activity.
Upvotes: 0