Home  >  Q&A  >  body text

Android realm在一个线程中插入数据,在另外一个线程中有时查到有时查不到数据

我在ui线程中存储数据,在子线程中用,为什么有时候查询到,有时候查询不到数据?

PHP中文网PHP中文网2741 days ago663

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-17 17:32:43

    The writing operation of Realm is asynchronous(?)... Then bind a Listener to the Result queried by the sub-thread to check whether it has been updated.

    reply
    0
  • 阿神

    阿神2017-04-17 17:32:43

    1. First of all, the IO operations involved should not be executed on the UI thread. 2. During asynchronous operations, there is no guarantee that the writing operation has been completed when reading. 3. The poster’s scenario is sequential. After the writing is successful, query again.

    reply
    0
  • Cancelreply