Buddy
Buddy

Reputation: 280

'SharedPreferencesUtils()' has private access in 'com.google.android.gms.common.util.SharedPreferencesUtils

why i am getting this error. I am trying to create session management for signup and login activity.

I got error in this line " pref = new SharedPreferencesUtils(context); "

help me to correct it.

here is my code -

import android.content.Context;
import android.content.SharedPreferences;

import com.google.android.gms.common.util.SharedPreferencesUtils;

public class SessionManagement {

    SharedPreferencesUtils pref;
    Context context;

    public SessionManagement(Context context) {
        this.context = context;
        pref = new SharedPreferencesUtils(context);

    }

    public void createLoginSession(String s, String s1, String s2, String s3, String s4, boolean b) {
    }
}

Upvotes: 0

Views: 192

Answers (1)

Taki
Taki

Reputation: 3730

This is sample of code from my project , follow these step :

  • Create function that will store the data
 // Call this function where you want to save your data

 private void storeCredentials(String email , String password) {
        SharedPreferences credentialsPrefs = getSharedPreferences("prefs", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = credentialsPrefs.edit();
        editor.putString("email",email);
        editor.putString("password",password);
        editor.apply();
    }
  • Then Call your preferences where you have your edittexts to set data
  SharedPreferences credentialsPrefs = getSharedPreferences("prefs", Context.MODE_PRIVATE);
        String email  = credentialsPrefs.getString("email","default-value");
        String password = credentialsPrefs.getString("password","default-       value");

Upvotes: 2

Related Questions