This is how I am inserting data into database using Room Persistence Library:
Entity:
@Entity
class User {
@PrimaryKey(autoGenerate = true)
p
Get the row ID by the following sniplet. It uses callable on an ExecutorService with Future.
private UserDao userDao;
private ExecutorService executorService;
public long insertUploadStatus(User user) {
Callable insertCallable = () -> userDao.insert(user);
long rowId = 0;
Future future = executorService.submit(insertCallable);
try {
rowId = future.get();
} catch (InterruptedException e1) {
e1.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return rowId;
}
Ref: Java Executor Service Tutorial for more information on Callable.