Tabnine Logo
Context.getSharedPreferences
Code IndexAdd Tabnine to your IDE (free)

How to use
getSharedPreferences
method
in
android.content.Context

Best Java code snippets using android.content.Context.getSharedPreferences (Showing top 20 results out of 7,488)

Refine searchRefine arrow

  • SharedPreferences.edit
  • SharedPreferences.getString
origin: JessYanCoding/MVPArms

/**
 * 返回存在sharedPreferences的信息
 *
 * @param key
 * @return
 */
public static String getStringSF(Context context, String key) {
  if (mSharedPreferences == null) {
    mSharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
  }
  return mSharedPreferences.getString(key, null);
}
origin: Tencent/tinker

/**
 * you can set Tinker disable in runtime at some times!
 *
 * @param context
 */
public static void setTinkerDisableWithSharedPreferences(Context context) {
  SharedPreferences sp = context.getSharedPreferences(ShareConstants.TINKER_SHARE_PREFERENCE_CONFIG, Context.MODE_MULTI_PROCESS);
  String keyName = ShareConstants.TINKER_ENABLE_CONFIG_PREFIX + ShareConstants.TINKER_VERSION;
  sp.edit().putBoolean(keyName, false).commit();
}
origin: stackoverflow.com

 private static String uniqueID = null;
private static final String PREF_UNIQUE_ID = "PREF_UNIQUE_ID";

public synchronized static String id(Context context) {
  if (uniqueID == null) {
    SharedPreferences sharedPrefs = context.getSharedPreferences(
        PREF_UNIQUE_ID, Context.MODE_PRIVATE);
    uniqueID = sharedPrefs.getString(PREF_UNIQUE_ID, null);
    if (uniqueID == null) {
      uniqueID = UUID.randomUUID().toString();
      Editor editor = sharedPrefs.edit();
      editor.putString(PREF_UNIQUE_ID, uniqueID);
      editor.commit();
    }
  }
  return uniqueID;
}
origin: robolectric/robolectric

@Test
public void commit_shouldStoreValues() throws Exception {
 editor.commit();
 SharedPreferences anotherSharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
 assertTrue(anotherSharedPreferences.getBoolean("boolean", false));
 assertThat(anotherSharedPreferences.getFloat("float", 666f)).isEqualTo(1.1f);
 assertThat(anotherSharedPreferences.getInt("int", 666)).isEqualTo(2);
 assertThat(anotherSharedPreferences.getLong("long", 666L)).isEqualTo(3L);
 assertThat(anotherSharedPreferences.getString("string", "wacka wa")).isEqualTo("foobar");
 assertThat(anotherSharedPreferences.getStringSet("stringSet", null)).isEqualTo(stringSet);
}
origin: guardianproject/haven

public PreferenceManager(Context context) {
  this.context = context;
  this.appSharedPrefs = context.getSharedPreferences(APP_SHARED_PREFS, AppCompatActivity.MODE_PRIVATE);
  this.prefsEditor = appSharedPrefs.edit();
}
origin: TommyLemon/APIJSON

/**
 * @param paramList
 * @return
 */
public String getToken(String tag) {
  return context.getSharedPreferences(KEY_TOKEN, Context.MODE_PRIVATE).getString(KEY_TOKEN + tag, "");
}
/**
origin: stackoverflow.com

 public class AppPreferences {
   public static final String KEY_PREFS_SMS_BODY = "sms_body";
   private static final String APP_SHARED_PREFS = AppPreferences.class.getSimpleName(); //  Name of the file -.xml
   private SharedPreferences _sharedPrefs;
   private Editor _prefsEditor;

   public AppPreferences(Context context) {
     this._sharedPrefs = context.getSharedPreferences(APP_SHARED_PREFS, Activity.MODE_PRIVATE);
     this._prefsEditor = _sharedPrefs.edit();
   }

   public String getSmsBody() {
     return _sharedPrefs.getString(KEY_PREFS_SMS_BODY, "");
   }

   public void saveSmsBody(String text) {
     _prefsEditor.putString(KEY_PREFS_SMS_BODY, text);
     _prefsEditor.commit();
   }
}
origin: GitLqr/LQRWeChat

private SPUtils(Context context) {
  this.context = context;
  sp = this.context.getSharedPreferences(SP_NAME, Context.MODE_APPEND);
  editor = sp.edit();
}
origin: TommyLemon/APIJSON

/**
 * @param paramList
 * @must demo_***改为服务器设定值
 * @return
 */
public String getToken(String tag) {
  return context.getSharedPreferences(KEY_TOKEN, Context.MODE_PRIVATE).getString(KEY_TOKEN + tag, "");
}
/**
origin: czy1121/update

public static void clean(Context context) {
  SharedPreferences sp = context.getSharedPreferences(PREFS, 0);
  File file = new File(context.getExternalCacheDir(), sp.getString(KEY_UPDATE, "") + ".apk");
  UpdateUtil.log("apk ==> " + file.toString());
  if (file.exists()) {
    file.delete();
  }
  sp.edit().clear().apply();
}
origin: JessYanCoding/MVPArms

/**
 * 存储重要信息到sharedPreferences;
 *
 * @param key
 * @param value
 */
public static void setStringSF(Context context, String key, String value) {
  if (mSharedPreferences == null) {
    mSharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
  }
  mSharedPreferences.edit().putString(key, value).apply();
}
origin: TommyLemon/APIJSON

/**
 * @return
 */
public String getCookie() {
  return context.getSharedPreferences(KEY_COOKIE, Context.MODE_PRIVATE).getString(KEY_COOKIE, "");
}
/**
origin: robolectric/robolectric

@Test
public void commit_shouldClearEditsThatNeedRemoveAndEditsThatNeedCommit() throws Exception {
 editor.commit();
 editor.remove("string").commit();
 assertThat(sharedPreferences.getString("string", "no value for key")).isEqualTo("no value for key");
 SharedPreferences anotherSharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
 anotherSharedPreferences.edit().putString("string", "value for key").commit();
 editor.commit();
 assertThat(sharedPreferences.getString("string", "no value for key")).isEqualTo("value for key");
}
origin: JessYanCoding/MVPArms

/**
 * 清除某个内容
 */
public static void removeSF(Context context, String key) {
  if (mSharedPreferences == null) {
    mSharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
  }
  mSharedPreferences.edit().remove(key).apply();
}
origin: TommyLemon/APIJSON

/**
 * @return
 */
public String getCookie() {
  return context.getSharedPreferences(KEY_COOKIE, Context.MODE_PRIVATE).getString(KEY_COOKIE, "");
}
/**
origin: JessYanCoding/MVPArms

/**
 * 存储重要信息到sharedPreferences;
 *
 * @param key
 * @param value
 */
public static void setIntergerSF(Context context, String key, int value) {
  if (mSharedPreferences == null) {
    mSharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
  }
  mSharedPreferences.edit().putInt(key, value).apply();
}
origin: TommyLemon/APIJSON

/**
 * @param tag
 * @must demo_***改为服务器设定值
 * @return
 */
public String getToken(String tag) {
  return context.getSharedPreferences(KEY_TOKEN, Context.MODE_PRIVATE).getString(KEY_TOKEN + tag, "");
}
/**
origin: jiangqqlmj/FastDev4Android

private SharedPreferencesHelper(Context context) {
  sp = context.getSharedPreferences(SHARED_PATH, Context.MODE_PRIVATE);
  editor = sp.edit();
}
origin: TommyLemon/APIJSON

/**
 * @return
 */
public String getCookie() {
  return context.getSharedPreferences(KEY_COOKIE, Context.MODE_PRIVATE).getString(KEY_COOKIE, "");
}
/**
origin: JessYanCoding/MVPArms

/**
 * 清除Shareprefrence
 */
public static void clearShareprefrence(Context context) {
  if (mSharedPreferences == null) {
    mSharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
  }
  mSharedPreferences.edit().clear().apply();
}
android.contentContextgetSharedPreferences

Popular methods of Context

  • getPackageName
  • getResources
  • getSystemService
  • obtainStyledAttributes
  • getApplicationContext
  • getString
  • getPackageManager
  • startActivity
  • getContentResolver
  • getAssets
  • getTheme
  • getCacheDir
  • getTheme,
  • getCacheDir,
  • startService,
  • sendBroadcast,
  • getFilesDir,
  • registerReceiver,
  • getApplicationInfo,
  • unregisterReceiver,
  • getExternalCacheDir

Popular in Java

  • Start an intent from android
  • getApplicationContext (Context)
  • getContentResolver (Context)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • JComboBox (javax.swing)
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • Runner (org.openjdk.jmh.runner)
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now