@Dao
public interface myDao{
@Delete
void delete(MyModel model);
}
Update: 如果要删除完整的表格,请调用以下功能,
@Query("DELETE FROM MyModel")
void delete();
Note: 此处 MyModel 是表名 .
1
使用clearAllTables()与RXJava如下,以避免 java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
6 回答
结合Dick Lucas所说的并从其他StackOverFlow帖子添加重置自动增量,我认为这可以工作:
您可以创建一个DAO方法来执行此操作 .
从Room
1.1.0
开始,您可以使用clearAllTables(),其中:如果要从Room中的表中删除条目,只需调用此函数,
Update: 如果要删除完整的表格,请调用以下功能,
Note: 此处 MyModel 是表名 .
使用clearAllTables()与RXJava如下,以避免
java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
使用 RxJava 在后台执行此任务时,我遇到了删除所有方法的问题 . 这就是我最终解决它的方式:
和