Exploring Android Version 2.2 by Mark L. Murphy

Exploring Android Version 2.2 by Mark L. Murphy

Author:Mark L. Murphy
Language: eng
Format: mobi, epub
Publisher: CommonsWare
Published: 2021-09-12T21:31:48+00:00


@Query("SELECT * FROM todos") fun all(): List<ToDoEntity> @Query("SELECT * FROM todos WHERE id = :modelId") fun find(modelId: String): ToDoEntity

In that case, those functions would be synchronous, blocking until the query is complete.

Instead, our functions wrap our desired return values in Flow, from Kotlin’s coroutines system. This has two key effects:

Room will perform the queries on a background thread and post the results to the Flow when the results are ready. Hence, our functions are asynchronous, returning immediately, rather than blocking waiting for the database I/O to complete.

So long as we have 1+ observers of the Flow, if we do other database operations that affect the todos table, Room will automatically deliver a new result to those observers via the Flow. So, if we insert or delete a row from our table, observers will get updated data, which (if appropriate) will reflect those data changes.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.