-4

I have several apps which use the same accout. The question is when i had more than one apps installed in my phone,how can i login without type username and password if one of the app had logged in.

Michael Yang
  • 1,403
  • 2
  • 18
  • 27

2 Answers2

-1

See below reference code which is having app1 & app2, so using shared preferences suppose you can store username & password in app1 & you can using it in another app2. Here I'm shwing how to access username, you can expand it as per your requirement.

Okay! using this code in Application 1 ( with package name is "com.sharedpref1" ) to store data with Shared Preferences.

 SharedPreferences prefs = getSharedPreferences("demopref",
                Context.MODE_WORLD_READABLE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString("username", strShareValue);
        editor.commit();

And using this code in Application 2 to get data from Shared Preferences in Application 1. We can get it because we use MODE_WORLD_READABLE in application 1:

try {
            con = createPackageContext("com.sharedpref1", 0);
            SharedPreferences pref = con.getSharedPreferences(
                    "demopref", Context.MODE_PRIVATE);
            String data = pref.getString("username", "No Value");
            displaySharedValue.setText(data);

        } catch (NameNotFoundException e) {
            Log.e("Not data shared", e.toString());
        }  
VVB
  • 7,363
  • 7
  • 49
  • 83
-1

I think, you could use Database for storing username and password, and share the database among your multiple apps, settings some field like is_logged_in with boolean value 1 when user is loggedin. On app launch, access the database, check for the field is_logged_in and display appropriate logged in view.

Community
  • 1
  • 1
FreeLancr
  • 36
  • 3