Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if current user is logged in android

Tags:

android

How to check if current user is logged in android. I have an external database, I have successfully connected it to the database. I need to check if the user is logged in or not

if user not logged will display {register activity} otherwise will display {my info activity}

like image 803
melwinpintoe Avatar asked Mar 20 '14 08:03

melwinpintoe


1 Answers

It can be done by sharedpreferences and if you want to do from database then take one Boolean and save log in info according to user id and then when you first time login then make it true and after that any time just fetch that Boolean and if true then {my info activity} other wise {register activity} simple is it dude :)

like this for using sharedpreferences when first time login then

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putBoolean("Islogin", Islogin).commit(); // islogin is a boolean value of your login status

and anytime when u want to get status then

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        boolean Islogin = prefs.getBoolean("Islogin", false); // get value of last login status

Now check

if(Islogin)
        {   // condition true means user is already login
            Intent i = new Intent(this, "your login activity");
            startActivityForResult(i, 1);
        }

else
{
    // condition false take it user on login form 
}
like image 85
Bhanu Sharma Avatar answered Oct 01 '22 13:10

Bhanu Sharma