Answer the question
In order to leave comments, you need to log in
How to start a timer in the background?
The task is this. There is an application in which fragment1 and fragment2 are present. Fragment1 has a timer that randomizes messages and displays them in the RecyclerView and in the BottomNavigationView - the counter of these same messages. Everything works fine until fragment2 opens. The timer stops working and updates the counter. Displaying the timer in the activity is not an option, because. RecyclerView cannot be updated from activity. How to make the timer work with any open fragment, where to put it?
Answer the question
In order to leave comments, you need to log in
keep the timer inside the ViewModel and network the value of the timer in LiveData, and from the fragment just subscribe to LiveData
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question