Answers for "android how to keep users logged in"

-1

android how to keep users logged in

// siyanda zama 

// you have to create a sharedpreference that will keep a value or boolean 
// in this instance we will use an integer as follows
//login page
sharedpreferences = getSharedPreferences("autoLogin", Context.MODE_PRIVATE);
        int j = sharedpreferences.getInt("key", 0);

        //Default is 0 so autologin is disabled
        if(j > 0){
            Log.i("Loogged in","your in");
            Intent activity = new Intent(getApplicationContext(), DashActivity.class);
            startActivity(activity);
        }
        else
        {
            Log.i("Not luck","your not in");
        }
        
// put the following code for the logout button
 SharedPreferences sharedPreferences;
                sharedPreferences = getActivity().getSharedPreferences("autoLogin", Context.MODE_PRIVATE);

                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putInt("key", 0);
                editor.apply();
                
// depending on whether you have a splash screen just send it to the login page
// it will then determine whether to stay there or to go to the next page
Posted by: Guest on June-19-2020

Code answers related to "android how to keep users logged in"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language