您好,登錄后才能下訂單哦!
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; } //存數據 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; } //取數據 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; } } //調用 //存入 SystemSharedpreferences systemSharedpreferences = new SystemSharedpreferences( getBaseContext()); boolean flage = systemSharedpreferences.saveMessage( name, age); //取出 SystemSharedpreferences systemSharedpreferences = new SystemSharedpreferences( getBaseContext()); Map<String, String> maps = systemSharedpreferences.getMessage();
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。