title: Get onPause & onResume like events at application/task level
body: <p>I was wondering what could be the reason for not having a callback at the application level  when an application goes to background  and comes to the foreground. <code>Activity</code> class's <code>onPause</code> and <code>onResume</code> are only called on the current top activity. If I want to stop some background task that has the application level scope, then there is no easy way I can stop it when the app goes to background. There is high demand for these event callbacks.</p>
  
  <p>Why doesn't Android have a app level callback on pause and resume of applications? Can it be implemented in Android at the task(activity stack) level if not at app level?</p>
  
  <h2>The real problem :</h2>
  
  <p>A background Timertask refreshes UI with data from web at regular intervals. When app is no longer in foreground I want to stop it. </p>
  
  <p>Currently I am putting the repeating code in a <code>BaseActivity</code>. This is at the activity level. The task stops and starts on each pause and resume of every activity and the event of app going to bg or coming to fg is hidden among one of these events, which I cannot know. I wanted to know if there is a better way of doing it, I mean knowing when the app has stopped being visible to the user.</p>