SHARE
TWEET

Untitled

a guest Jan 14th, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Override
  2.     protected void onCreate(Bundle savedInstanceState) {
  3.         super.onCreate(savedInstanceState);
  4.         setContentView(R.layout.activity_main);
  5.         logoutButton = findViewById(R.id.logoutButton);
  6.  
  7.         logoutButton.setOnClickListener(v -> {
  8.             if (logoutButton.getText().toString().equals("Login")) {
  9.                 startActivity(new Intent(MainActivity.this, LoginActivity.class));
  10.             } else {
  11.                 logout();
  12.                 startActivity(new Intent(MainActivity.this, LoginActivity.class));
  13.  
  14.             }
  15.  
  16.         });
  17.     }
  18.  
  19.     private void logout() {
  20.         SharedPreferences preferences = getSharedPreferences(SHARED, Context.MODE_PRIVATE);
  21.         SharedPreferences.Editor editor = preferences.edit();
  22.         editor.clear();
  23.         editor.apply();
  24.         Toast.makeText(this, R.string.logoutToast, Toast.LENGTH_SHORT).show();
  25.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top