question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[master] Filtering state is lost across process death

See original GitHub issue

Value 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JoseAlcerrecacommented, Jan 28, 2020

They are, my bad. I was simulating process death incorrectly.

0reactions
Zhuindencommented, Jan 24, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found