title: How do I return to previous app after a service generated activity is 'finished'
body: <p>My app has a service that runs in the background.  It wakes up on intent from the user which is typically generated from another application (such as sharing to my app from the web browser).  After the service is done performing a task I want it to open an Activity that displays some info about the task that was completed.  When the user is done looking at this info, I want them to be able to hit 'Back' or 'Close' and return to what they were doing previously (not within my application).  </p>
  
  <p>I've only managed to get the activity to close leaving my App's main activity front and center on the screen.  This only happens if the app is still running. If it's been killed then it correctly returns to the web browser where the user intent was generated from.</p>
  
  <p>How can I make the 'Back' button close the activity and return to the previous app from which this entire workflow was started?</p>
  
  <p>EDIT:</p>
  
  <p>This is the code I am executing from within the android service:</p>
  
  <pre><code>Intent intent = new Intent(this, TestActivity.class);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
  startActivity(intent);
  </code></pre>
  
  <p>When I tap the back button from the <code>TestActivity</code> it returns me to the main activity of my app, not the previous app I was in when the service started <code>TestActivity</code>.</p>