private static void setAnywayTimer ( Context context ) { AlarmManager am = ( AlarmManager ) context . getSystemService ( Context . ALARM_SERVICE ) ; Intent intent = new Intent ( context , IdleReceiver . class ) ; intent . setAction ( ACTION_TRIGGER_IDLE ) ; PendingIntent pendingIntent = PendingIntent . getBroadcast ( context , 0 , intent , 0 ) ; final long nowElapsed = SystemClock . elapsedRealtime ( ) ; final long when = nowElapsed + INACTIVITY_ANYWAY_THRESHOLD ; compatSetWindow ( am , AlarmManager . ELAPSED_REALTIME_WAKEUP , when , IDLE_WINDOW_SLOP , pendingIntent ) ; }
We can t get idle broadcasts while the app is not running . Since our app will probably be killed before the device becomes idle let s set an alarm sometime in the future that will force an idle check .