DurgaPrasad Ganti
DurgaPrasad Ganti

Reputation: 1008

How to close Application in android

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

Answers (4)

user2699728
user2699728

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

SMR
SMR

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

Angel
Angel

Reputation: 902

Intent activity= new Intent(FirstActivity.this,SecondActivity.class);

finish();            //This is used to close first activity

startActivity(activity);

Upvotes: 0

Waqar Ahmed
Waqar Ahmed

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

Related Questions