Seamlessly swapping Activity and Service and back
<p>I want to start a service once my activity is put in the background (home button is pressed, or the activity is interrupted in any other way), and stop the service once my activity is back in the foreground.</p>

<p>Placing the start and stop of the service in any of the Activity lifecycle callbacks (starting in onPause and stopping in onResume, for example) isn't very good, since they are being called also on orientation change, and I don't want to start the service and immediately stop it.</p>

<p>Also, I don't want to run the service in the background all the time, but only when the activity is not visible.</p>

<p>What is the best practice for this use case?</p>
