1

データベースを使用せずにオブジェクトを保存する最も簡単な方法は何ですか?

たとえば、戻ってホテルを追加または削除できるリストを保存したいのですが、データベースを作成したくないので、面倒なことはすべてやり過ぎのようです。

配列リストを共有設定または同様に簡単に保存するにはどうすればよいですか?

public class Hotel{
  String id, name, address, phoneNumber;
  public String getName(){
    return name;
  }
etc
}
4

2 に答える 2

5

私のアドバイス:

  1. Gsonを使用して、任意のタイプのオブジェクトを String に変換します
  2. その文字列を SharedPreferences に保存します
  3. Gson を使用してプロセスを逆にしてオブジェクトを取得します
于 2013-02-09T15:33:55.623 に答える
1
//Retrieve the values
Set<String> set = new HashSet<String>();
set = myScores.getStringSet("key", null);

//Set the values
Set<String> set = new HashSet<String>();
set.addAll(listOfExistingScores);
scoreEditor.putStringSet("key", set);
scoreEditor.commit();
于 2013-02-09T15:42:35.823 に答える