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
// The context is Android context; GROUP_ID can be regarded as the file name of SharedPreferences
APSharedPreferences mAPSharedPreferences = SharedPreferencesManager.getInstance(context, GROUP_ID);
Query data
/**
* Initialize the data of key-value pairs
*/
private void initData() {
mData.clear();
try {
// Get the information of all key-value pairs
mData.putAll((Map<String, String>) mAPSharedPreferences.getAll());
} catch (Exception e) {
e.printStackTrace();
}
}
Insert data
/**
* Insert key-value pairs
*
* @param key key
* @param value value
*/
private void insertKeyValue(String key, String value) {
mAPSharedPreferences.putString(key, value);
mAPSharedPreferences.commit();
}
Delete data
/**
* Delete key-value pairs
*
* @param key key
*/
private void deleteKeyValue(String key) {
mAPSharedPreferences.remove(key);
mAPSharedPreferences.commit();
}