Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- logoutButton = findViewById(R.id.logoutButton);
- logoutButton.setOnClickListener(v -> {
- if (logoutButton.getText().toString().equals("Login")) {
- startActivity(new Intent(MainActivity.this, LoginActivity.class));
- } else {
- logout();
- startActivity(new Intent(MainActivity.this, LoginActivity.class));
- }
- });
- }
- private void logout() {
- SharedPreferences preferences = getSharedPreferences(SHARED, Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = preferences.edit();
- editor.clear();
- editor.apply();
- Toast.makeText(this, R.string.logoutToast, Toast.LENGTH_SHORT).show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement