Fill the blank
Expose the saved query as a StateFlow.
class SearchViewModel(private val handle: SavedStateHandle) : ViewModel() {
val query: StateFlow<String> = handle.____("query", "")
fun onQuery(q: String) { handle["query"] = q }
}Hint 1 of 1
You want a stream that updates when the value is set.
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A getStateFlow
Correct. It returns a StateFlow backed by the saved value.
Why not the others?
- B getLiveData. That returns LiveData, not a StateFlow.
- C get. get returns the current value once, not a stream.
- D remove. That deletes the key.