All Products
Search
Document Center

Mobile Platform as a Service:Key-value pair storage

Last Updated:May 10, 2021

The key-value pair storage provided by mPaaS is similar with native Android SharedPreferences, providing a similar interface. The underlying is the key-value-pair storage system implemented by mPaaS.

Examples

Create APSharedPreferences

  1. // The context is Android context; GROUP_ID can be regarded as the file name of SharedPreferences
  2. APSharedPreferences mAPSharedPreferences = SharedPreferencesManager.getInstance(context, GROUP_ID);

Query data

  1. /**
  2. * Initialize the data of key-value pairs
  3. */
  4. private void initData() {
  5. mData.clear();
  6. try {
  7. // Get the information of all key-value pairs
  8. mData.putAll((Map<String, String>) mAPSharedPreferences.getAll());
  9. } catch (Exception e) {
  10. e.printStackTrace();
  11. }
  12. }

Insert data

  1. /**
  2. * Insert key-value pairs
  3. *
  4. * @param key key
  5. * @param value value
  6. */
  7. private void insertKeyValue(String key, String value) {
  8. mAPSharedPreferences.putString(key, value);
  9. mAPSharedPreferences.commit();
  10. }

Delete data

  1. /**
  2. * Delete key-value pairs
  3. *
  4. * @param key key
  5. */
  6. private void deleteKeyValue(String key) {
  7. mAPSharedPreferences.remove(key);
  8. mAPSharedPreferences.commit();
  9. }