- insertはUIスレッドでなく、Workerスレッドで行う(AsyncTaskを使った)
- primary key(= id)はauto incrementにしとくのが無難そう
- マイグレーションが賢くてビビった ActiveAndroidとは何だったのか
- Setterの正しい書き方がわかんなかったけど適当に書いたら動いた
final OrmaDatabase orma = OrmaDatabase.builder(this) .build(); final Todo todo = new Todo(1,"hoge title","hoge content",false, "hoge desc"); AsyncTask<String,Void,String> task = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... strings) { Log.v("log","insert to table"); orma.insertIntoTodo(todo); return null; } @Override protected void onPostExecute(String s) { Log.v("log","finished update"); } }; task.execute();
@Table public class Todo { @PrimaryKey(autoincrement = true) public long id; @Column(indexed = true) public String title; @Column public String content; @Column(indexed = true) public boolean done; @Nullable @Column public String description; @Setter public Todo(long id, String title, String content, boolean done, String description) { this.id = id; this.title = title; this.content = content; this.done = done; this.description = description; } }