Search code examples
androidbackground-processandroid-recents

Is it possible to check how long app is in background?


I want to quit my application if it stays in background for 5 minutes. Is it possible to do that programmatically?


Solution

  • Its possible, run a background service with a timer task which checks the state of the application for a specified time period. This would be generally done using a BaseActivity and overriding onStop() and onWindowFocusChanged() Methods. Find more info here and here