Search code examples
javaandroidtimerlifecycleonpause

Is there an onPause for the entire application?


My application is a set of Activities and I have not subclassed Application. There is a static singleton class that runs a recurring timer (java.util.Timer). That timer needs to be paused when the user leaves my application.

If there were only one activity, I could pause and resume the timer onPause() and onResume() of MainActivity. How should I solve this problem in my case?


Solution

  • I found that onDestroy and onCreate are called appropriately, so I overrode those.

    Overriding onPause and onStart for all activities would be troublesome since the timer would be paused and resumed every time a new activity was launched.