I would like to create a CountdownTimer
which will trigger events that will update the UI (trigger popup, start an animation, etc.).
I wonder how to do this clean, here are my hypothesis and why :
- A separate component
EventCountdownTimer
. I could then benefit the use ofLifecycleObserver
, but I wonder how to communicate the information back to the activity (I tried extendingCountdownTimer
and using it in the activity but I have an error and can't get it to compile) - In the
Activity
itself, it's the simplest but I'm not sure it belongs there as it isn't a UI component and I can't benefit theLifecycleObserver
- In the
ViewModel
. I thought as it's activity related and theCountdownTimer
is kinda logic data, it should go in here, but that means also watching the lifecycle of the activity, and holding anyActivity
related field withinViewModel
is bad practice.
What's the best option according to you? And why?