title: The issue is,it takes 3 seconds.I want to check foreground app every 1000milliseconds#THANKS_IN_ADVANCE
body: <pre><code>UsageEvents usageEvent = mUsageStatsManager.queryEvents(time - 100 * 1000, time);
  UsageEvents.Event event = new UsageEvents.Event();
  // get last event
  while (usageEvent.hasNextEvent()) {
    usageEvent.getNextEvent(event);
  }
  if (topPackageName.equals(event.getPackageName()) &amp;&amp; event.getEventType() ==
      UsageEvents.Event.MOVE_TO_FOREGROUND) {
    pActivity = topPackageName;
  }
  </code></pre>