简体   繁体   中英

programing "back-button" in Android

I programmed "back button" in Android using this code:

@Override
public void onBackPressed() {
   Log.d("CDA", "onBackPressed Called");
   Intent setIntent = new Intent(getApplicationContext(),TabsActivity.class);
   startActivity(setIntent);
}

And it works OK. but I have problem with "Log-out" in my app after I program "back button", when user wants to log-out, "TabsActivity.class" opened, then app stopped! This code used for log-out user. And it worked good before programming "back button".

        ParseUser.logOut();
        finish();

Thank you ^^

Do Something Like

Activity

 public class youractivity extends Activity {
 /*Your Declaration's here*/
 public int isLoggedIn;

 /*Your Functions here*/
 private loginFunction()
 { 
   parseUser.logIn();
   isLoggedIn=1; 
 }

 private logoutFunction()
 { 
   parseUser.logOut();
   isLoggedIn=0; 
 }

 @Override
 public void onBackPressed() {
  if(isLoggedIn==1){
    Log.d("CDA", "onBackPressed Called");
    Intent setIntent = new Intent(getApplicationContext(),TabsActivity.class);
    startActivity(setIntent);
      }
  else
  super.onBackPressed();
  }

I fixed my problem, Thank you. Just I used this code for logout:

        ParseUser.logOut();
        ParseUser.logOut();
        Intent intent = new Intent(this, FirstScreenActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();

Thanx every one ;)

Intent setIntent = new Intent(getApplicationContext(),TabsActivity.class);
setIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | 
Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_NEW_TASK);                                 
startActivity(z);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM