There is a MainActivity with a login form, a button with such a code and a transition to the next window.
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE); SharedPreferences.Editor ed = sharedPreferences.edit(); ed.putString("SAVED_TOKEN", token); ed.putBoolean("IS_AUTHORIZED", true); ed.apply(); And there is a transition to User_Main in the manifest indicated here
android:noHistory="true" and in User_Main there is a button with logout with return to the previous one, MainActivity
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE); SharedPreferences.Editor ed = sharedPreferences.edit(); ed.putBoolean("IS_AUTHORIZED", false); ed.apply(); Intent intent_logout=new Intent(User_Main.this,MainActivity.class); startActivity(intent_logout); in OnCreate in MainActivity we are checking for "IS_AUTHORIZED"
SharedPreferences sharedPreferences =getPreferences(Context.MODE_PRIVATE); boolean isAuthodized = sharedPreferences.getBoolean("IS_AUTHORIZED", false); if (isAuthodized){ Intent intent=new Intent(MainActivity.this,User_Main.class); startActivity(intent); } When logouting for some reason, I stay in place, and the windows do not change and the problem in the OnCreate block is visible. And the task is simple, if the user logged in, then after folding and opening, the User_Main opens, if the user logs out, then MainActivity
I do it for the first time, I can not catch up with how to implement correctly.