您好,登錄后才能下訂單哦!
import java.util.HashMap; import java.util.Map; import android.content.Context; import android.content.SharedPreferences; public class SystemSharedpreferences { private Context context; public SystemSharedpreferences(Context context) { this.context = context; } //存數(shù)據(jù) public boolean saveMessage(String name,String age){ boolean flage = false; SharedPreferences sharedpreferences = context.getSharedPreferences("IPConfig",Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString("name", name); editor.putString("age", age); flage = editor.commit(); return flage; } //取數(shù)據(jù) public Map<String,String> getMessage(){ Map<String,String> map = new HashMap<String,String>(); SharedPreferences sharedPreferences = context.getSharedPreferences("IPConfig", Context.MODE_PRIVATE); String ip = sharedPreferences.getString("name", ""); String port = sharedPreferences.getString("age", ""); map.put("name",name); map.put("age", age); return map; } } //調(diào)用 //存入 SystemSharedpreferences systemSharedpreferences = new SystemSharedpreferences( getBaseContext()); boolean flage = systemSharedpreferences.saveMessage( name, age); //取出 SystemSharedpreferences systemSharedpreferences = new SystemSharedpreferences( getBaseContext()); Map<String, String> maps = systemSharedpreferences.getMessage();
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。