SharedPreferencesパスワードを覚えておくなど、一時的にデータを保存
1728 ワード
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();