[master] Filtering state is lost across process death
See original GitHub issueValue of _currentFiltering
is never persisted to Bundle. If one were to use SavedStateHandle
to solve, this, the solution would look like this:
class TasksViewModel(
private val tasksRepository: TasksRepository,
private val savedStateHandle: SavedStateHandle
): ViewModel() {
private val selectedFilter: MutableLiveData<TasksFilterType> = savedStateHandle.getLiveData("filterType")
val items: LiveData<List<Task>> = selectedFilter.switchMap { filterType ->
tasksRepository.getTasks(filterType)
}
}
The Repository (or getTaskUseCase
, whichever is used) should select the right DAO method to call for getting filtered results from Room DAO
class TaskRepository(
private val taskDao: TaskDao
) {
fun getTasks(filterType: TasksFilterType): LiveData<List<Task>> = when(filterType) {
ALL -> taskDao.getAllTasks()
ACTIVE_ONLY -> taskDao.getActiveTasks()
COMPLETED_ONLY -> tasks.getCompletedTasks()
}
}
And the DAO should expose LiveData with the correct filters
@Query("SELECT * FROM Tasks")
fun getAllTasks(): LiveData<List<Task>>
@Query("SELECT * FROM Tasks WHERE completed = 1")
fun getCompletedTasks(): LiveData<List<Task>>
@Query("SELECT * FROM Tasks WHERE completed = 0")
fun getActiveTasks(): LiveData<List<Task>>
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
[master] Filtering state is lost across process death · Issue #663
Now with the ViewModel-SavedState module reaching 1.0.0, the filtering can be persisted using SavedStateHandle. architecture-samples/app/src/ ...
Read more >Section 2: Calculation of Loss (Compensation) - VCF.gov
Economic loss is pecuniary loss caused by an eligible condition: loss of earnings or other benefits related to employment, the cost to replace...
Read more >Android Studio, logcat cleans after app closes - Stack Overflow
So when your app crashes during testing, that process is gone, so the filter clears the log. Instead, select "Edit Filter Configuration.
Read more >Index Catalog // ScholarWorks - California State University
Masters Thesis. Death, Dying, Drama, and Despair. Written in two different mediums, the following collection explores different types of grief and loss.
Read more >FILTER - Celonis Documentation
If a query is sent to Celonis, all active filters are propagated to the requested table(s). Multiple filters on a table are merged...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
They are, my bad. I was simulating process death incorrectly.
No support for enums? that’s odd, enums should (or I would expect them to) fall back to
putSerializable
. 🤔If this is intended, then that is quite an unfortunate limitation. One could use the enum name or ordinals I guess but that is still inconvenient.