How to run a service only when the user/phone is active?
<p>I want to run a <code>Service</code> only when the user is active or more general: when the phone is active. There is no need that the service runs when the screen is off. But as soon as the user unlocks his phone, I want the service to run again.</p>

<p>How do I achieve this behaviour?</p>

<p>My actual task: I want to capture logcat. Therefore I created a <code>Service</code> which spawns a thread that reads the output of the "logcat" process.</p>

<p>How exactly does that background thread behave when the phone gets locked? It does not hold any wake locks or stuff. Will Android pause the thread when the phone goes to sleep or will that thread keep Android from going to sleep? How will it be resumed after the phone awakes?</p>

<p>I also thought about registering an alarm via ´AlarmManager´ that fires every 15 minutes and parses the logcat. But with this approach I will likely miss some of the logcat lines.</p>
