2013年8月23日 星期五

Store perminant data in Android

There are basically 3 ways to save data in Android. The one I'm going to talk about here is SharedPreferences method. Before expanding the usage, be aware of that  SharedPreferences method does not apply across multiple processes.The following is the snippet:

import android.content.SharedPreferences;
...
private SharedPreferences mKeyAppMap;
...
mKeyAppMap = mContext.getSharedPreferences(HOTKEY_PREF_NAME, 0);
...
String AppName = mKeyAppMap.getString(targetName,"none"); <-- Get data
...

SharedPreferences.Editor editor = mKeyAppMap.edit(); <-- Save data

editor.putString(key, appName);
editor.commit();

Reference links
http://www.ozzysun.com/2010/11/android.html
http://developer.android.com/training/basics/data-storage/index.html

沒有留言:

張貼留言