Advertisement
Guest User

Untitled

a guest
Jan 14th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  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.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement