Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
Defining UI State
For a little bit of polish, pre-populate the search text box with the saved query when the user presses the search icon to expand the search view.
Unfortunately, there is not a great way for you to access your stored query at the same time that you initialize your search view. Since DataStore exposes its data asynchronously, there is no good way to access its value during the creation of a fragment. In Chapter 12, you read from your on-disk databases asynchronously to avoid blocking the main thread. Because DataStore is backed by on-disk storage, these same performance concerns apply – and mean that you need coroutines once more.
You have already seen how to send asynchronous values to your UI by leveraging StateFlow ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access