android.content.SharedPreferences.getAll()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中android.content.SharedPreferences.getAll()方法的一些代码示例,展示了SharedPreferences.getAll()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SharedPreferences.getAll()方法的具体详情如下:
包路径:android.content.SharedPreferences
类名称:SharedPreferences
方法名:getAll

SharedPreferences.getAll介绍

[英]Retrieve all values from the preferences.

Note that you must not modify the collection returned by this method, or alter any of its contents. The consistency of your stored data is not guaranteed if you do.
[中]从首选项中检索所有值。
请注意,您不得修改此方法返回的集合,或更改其任何内容。如果这样做,则无法保证存储数据的一致性。

代码示例

代码示例来源:origin: libgdx/libgdx

@Override
public Map<String, ?> get () {
  return sharedPrefs.getAll();
}

代码示例来源:origin: libgdx/libgdx

@Override
public Map<String, ?> get () {
  return sharedPrefs.getAll();
}

代码示例来源:origin: smuyyh/BookReader

public Map<String, ?> getAll() {
  return this.prefs.getAll();
}

代码示例来源:origin: TommyLemon/APIJSON

/**获取列表大小
 * @return
 */
public int getSize() {
  Map<String, ?> map = sp.getAll();
  return map == null ? 0 : map.size();
}

代码示例来源:origin: TommyLemon/Android-ZBLibrary

/**获取列表大小
 * @return
 */
public int getSize() {
  Map<String, ?> map = sp.getAll();
  return map == null ? 0 : map.size();
}

代码示例来源:origin: facebook/stetho

public static Set<Entry<String, ?>> getSharedPreferenceEntriesSorted(SharedPreferences preferences) {
 TreeSet<Entry<String, ?>> entries = new TreeSet<>(new Comparator<Entry<String, ?>>() {
  @Override
  public int compare(Entry<String, ?> lhs, Entry<String, ?> rhs) {
   return lhs.getKey().compareTo(rhs.getKey());
  }
 });
 entries.addAll(preferences.getAll().entrySet());
 return entries;
}

代码示例来源:origin: facebook/stetho

@Override
 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
  Object value = sharedPreferences.getAll().get(key);
  Toast.makeText(
    MainActivity.this,
    getString(R.string.pref_change_message, key, value),
    Toast.LENGTH_SHORT).show();
 }
};

代码示例来源:origin: facebook/stetho

public DevToolsSharedPreferencesListener(SharedPreferences prefs, String tag) {
 mPrefs = prefs;
 mStorageId = new DOMStorage.StorageId();
 mStorageId.securityOrigin = tag;
 mStorageId.isLocalStorage = true;
 mCopy = prefsCopy(prefs.getAll());
}

代码示例来源:origin: TommyLemon/APIJSON

/**ROOT
 * 获取列表
 * @return
 */
@SuppressWarnings("unchecked")
public Map<String, String> getMap() {
  try {
    return (Map<String, String>) sp.getAll();
  } catch (Exception e) {
    Log.e(TAG, "getMap try { return (Map<String, String>) sp.getAll();" +
        "}catch(Exception e) {\n " + e.getMessage());
  }
  return null;
}

代码示例来源:origin: GitLqr/LQRWeChat

@Override
public List<Cookie> loadAll() {
  List<Cookie> cookies = new ArrayList<>(sharedPreferences.getAll().size());
  for (Map.Entry<String, ?> entry : sharedPreferences.getAll().entrySet()) {
    String serializedCookie = (String) entry.getValue();
    Cookie cookie = new SerializableCookie().decode(serializedCookie);
    if (cookie != null) {
      cookies.add(cookie);
    }
  }
  return cookies;
}

代码示例来源:origin: wequick/Small

@Override
public void onCreate() {
  super.onCreate();
  Log.d(TAG, "onCreate()");
  // Test shared data
  Log.d(TAG, this.getSharedPreferences("small.app-versions", 0).getAll().toString());
  // Test resources
  String s = this.getString(R.string.action_settings);
  Log.d(TAG, s);
}

代码示例来源:origin: k9mail/k-9

@Override
public void copy(android.content.SharedPreferences input) {
  Map < String, ? > oldVals = input.getAll();
  for (Entry < String, ? > entry : oldVals.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
    if (key != null && value != null) {
      Timber.d("Copying key '%s', value '%s'", key, value);
      changes.put(key, "" + value);
    } else {
      Timber.d("Skipping copying key '%s', value '%s'", key, value);
    }
  }
}

代码示例来源:origin: facebook/facebook-android-sdk

public Bundle load() {
  Bundle settings = new Bundle();
  Map<String, ?> allCachedEntries = cache.getAll();
  for (String key : allCachedEntries.keySet()) {
    try {
      deserializeKey(key, settings);
    } catch (JSONException e) {
      // Error in the cache. So consider it corrupted and return null
      Logger.log(LoggingBehavior.CACHE, Log.WARN, TAG,
          "Error reading cached value for key: '" + key + "' -- " + e);
      return null;
    }
  }
  return settings;
}

代码示例来源:origin: hidroh/materialistic

public static void sync(PreferenceManager preferenceManager) {
  Map<String, ?> map = preferenceManager.getSharedPreferences().getAll();
  for (String key : map.keySet()) {
    sync(preferenceManager, key);
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void getAll_shouldReturnAllValues() throws Exception {
 editor.commit();
 assertThat(sharedPreferences.getAll()).hasSize(6);
 assertThat(sharedPreferences.getAll().get("int")).isEqualTo(2);
}

代码示例来源:origin: hidroh/materialistic

private void syncDeferredItems() {
  Set<String> itemIds = mSharedPreferences.getAll().keySet();
  for (String itemId : itemIds) {
    scheduleSync(mContext, new JobBuilder(mContext, itemId).setNotificationEnabled(false).build());
  }
}

代码示例来源:origin: square/assertj-android

public S doesNotContain(String key, int value) {
 isNotNull();
 assertThat(actual.getAll())
   .overridingErrorMessage("Expected preferences not to contain <%s> but it does.",
     stringOf(key, value))
   .doesNotContain(MapEntry.entry(key, value));
 return myself;
}

代码示例来源:origin: square/assertj-android

public S doesNotContain(String key, long value) {
 isNotNull();
 assertThat(actual.getAll())
   .overridingErrorMessage("Expected preferences not to contain <%s> but it does.",
     stringOf(key, value))
   .doesNotContain(MapEntry.entry(key, value));
 return myself;
}

代码示例来源:origin: robolectric/robolectric

@Before
public void setUp() {
 context = ApplicationProvider.getApplicationContext();
 sharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
 // Ensure no shared preferences have leaked from previous tests.
 assertThat(sharedPreferences.getAll()).hasSize(0);
 editor = sharedPreferences.edit();
 editor.putBoolean("boolean", true);
 editor.putFloat("float", 1.1f);
 editor.putInt("int", 2);
 editor.putLong("long", 3L);
 editor.putString("string", "foobar");
 stringSet.add( "string1" );
 stringSet.add( "string2" );
 stringSet.add( "string3" );
 editor.putStringSet("stringSet", stringSet);
}

代码示例来源:origin: hidroh/materialistic

@Test
public void testSyncEnabledNonWifi() throws IOException {
  Call<HackerNewsItem> call = mock(Call.class);
  when(call.execute()).thenThrow(IOException.class);
  when(TestRestServiceFactory.hnRestService.cachedItem(any())).thenReturn(call);
  setNetworkType(ConnectivityManager.TYPE_MOBILE);
  syncScheduler.scheduleSync(service, "1");
  adapter.onPerformSync(mock(Account.class), getLastSyncExtras(), null, null, null);
  // should defer
  assertThat(syncPreferences.getAll()).isNotEmpty();
}

相关文章