Room persistance library. Delete all

前端 未结 8 1118
再見小時候
再見小時候 2020-12-04 11:59

How can I delete all entries on specific table using Room Persistence Library? I need to drop table, but I cannot to find any information how to do this.

Only when d

8条回答
  •  一向
    一向 (楼主)
    2020-12-04 12:15

    Use clearAllTables() with RXJava like below inorder to avoid java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.

    Completable.fromAction(new Action() {
            @Override
            public void run() throws Exception {
                getRoomDatabase().clearAllTables();
            }
        }).subscribeOn(getSchedulerProvider().io())
                .observeOn(getSchedulerProvider().ui())
                .subscribe(new Action() {
                    @Override
                    public void run() throws Exception {
                        Log.d(TAG, "--- clearAllTables(): run() ---");
                        getInteractor().setUserAsLoggedOut();
                        getMvpView().openLoginActivity();
                    }
                }, new Consumer() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        Log.d(TAG, "--- clearAllTables(): accept(Throwable throwable) ----");
                        Log.d(TAG, "throwable.getMessage(): "+throwable.getMessage());
    
    
                    }
                });
    

提交回复
热议问题