title: Android Best Way to Detect and Handle User INACTIVITY
body: <p>Inactivity is a very important EVENT.   For many apps if the user does not interact with it for a certain number of seconds its time to reset the app and go back to main activity logout, or conserve power.  So I would really like to get some feedback on the best way to detect this.  In fact I think everyone will benefit from a good solution to this.</p>
  
  <p>So my question is twofold:</p>
  
  <p>1) Is there a better way to detect user inactivity than using a combination of 
     activity.onUserInteraction()  to reset a CountDownTimer?</p>
  
  <p>Note: One reported downside to this approach is that softkeypad interaction might not be
           caught by this approach.</p>
  
  <p>Note: Another reported downside is the CountDownTimer is off main thread and might not update
           correctly.  I am not sure how big an issue this is?</p>
  
  <p>Note:  CountDownTimer appears to have cancellation issues as well:
            <a href="https://stackoverflow.com/questions/3138348/how-to-stop-cancel-android-countdowntimer">how to stop/cancel android CountDownTimer</a></p>
  
  <p>2) Lets say that onUserInteraction()/CountDownTimer is the best/only solution to this problem
     there are still some questions:</p>
  
  <p>a) should each activity launch its own countdown timer?</p>
  
  <p>b) Should a single countdown timer be restarted in the onCreate method of each activity?</p>
  
  <p>c) lets say I want to dim the screen or goto main activity when the countdown expires where
        should the timeout handler be located?  In each activity? In a service?</p>
  
  <p>Thanks</p>