search

Home  >  Q&A  >  body text

android - GreenDAO的数据库操作需要在子线程完成吗?

刚开始使用GreenDao,不是很熟悉。还有一个就是,更新数据之后要怎么才能立即刷新数据呢?

怪我咯怪我咯2950 days ago1669

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 17:39:19

    GreenDao provides a unified interface class AsyncSession for asynchronous operations, which provides all the asynchronous operation methods you need.
    You can get an AsyncSession instance by calling DaoSession.startAsyncSession().

    DBManager.getInstance().getDaoSession().startAsyncSession().runInTx(new Runnable() {
    
                @Override
                public void run() {
                    //DELETE
                    //DELETE
                    //UPDATE
    
                }
            });

    You can also open a thread yourself.

    Batch database operations can use GreenDao transactions.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:39:19

    All time-consuming operations in Android should be placed in child threads. Reading and writing databases are time-consuming operations.

    After data acquisition, use the corresponding adapter to refresh it.

    reply
    0
  • PHPz

    PHPz2017-04-17 17:39:19

    Many operations of the realm database can be done on the main thread

    reply
    0
  • Cancelreply