-1

I have made an option in menu item to sign out from an activity and it will be redirected to Login page. However, when back button is pressed, it shows the activity which supposed to be shown only after signed in. Please advice what went wrong. The menu code is given below

public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case R.id.exit:
            uAuth.signOut();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56
KAL
  • 41
  • 2
  • 9

3 Answers3

1

Providing the code which opens the new login activity and closes the current one is more appropriate than menu item select code, BTW you can use the code provided in this answer to do so

XamarinDev
  • 66
  • 7
0

Call finish(); after uAuth.signOut(). It'll remove the current activity from the stack and your login activity will be on the top of the stack.

Alok Bharti
  • 136
  • 1
  • 8
0

Can you provide your code for uAuth? Seems like your not implementing a session controller for your app. You can use SharedPreferences to store a session_id and check the session_id on a activity to test if a user is currently logged in or not.

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
                        SharedPreferences.Editor editor = preferences.edit();
                        editor.putString("session", "yoursession_maybe_a_userid");
                        editor.apply();

And if you want to check the value for your session you can use

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = preferences.edit();
        String session = preferences.getString("session", "");

and just check the value for String session. Happy coding.