0

Question mainly on design.

In my game i have a timer that give the user something each x minutes. After triggering, it starts again. Currently i use count down timer and utilize the onTick and onFinish.

The problem is that i dont want this timer to work when app goes to background. The obvious solution will be to stop it on the onPause call back - the problem is that my app have multiple activities and i dont want to stop/start the timer on each activity change.

Is there other class better for that use-case? how can i make detect app goes to background?

Michael A
  • 5,770
  • 16
  • 75
  • 127
  • so u care about stopping the timer only when the entire app stops, right? – Alan Deep May 15 '20 at 12:10
  • @AlanDeep correct – Michael A May 15 '20 at 12:14
  • You know in every app there is a MainActivity, so the timer should be stopped there in onStop() and you should be able to start this timer from all the other activities because you're sure it's there an initialized..correct me if i'm wrong somewhere please.. – Alan Deep May 15 '20 at 12:16
  • Try using[`ProcessLifecycleOwner`](https://developer.android.com/reference/androidx/lifecycle/ProcessLifecycleOwner) – Pawel May 15 '20 at 12:18

0 Answers0