title: Why does starting an activity from a widget cause my main activity to start as well?
body: <p>When I start an activitiy from a widget I want the back button to go to the home screen but instead it goes to the app's main activity. After toying around I found that if I somehow close the main app activity, this problem doesn't occur. Strange.</p>
  
  <p>I found a solution <a href="https://stackoverflow.com/questions/2761673/widget-starting-a-service-also-starts-main-activity">here</a> that said to call finish(); in my main activity's onPause(). Obviously this is the wrong solution e.g. reorientation of the screen causes an onPause() so the will activity will die whenever the phone is rotated.</p>
  
  <p>This is how I start my activity:</p>
  
  <pre><code>@Override
  public void onReceive(Context context, Intent intent) {
      [...]
          //new Emergency().emDialog(context).show();
          Intent myIntent = new Intent(context, EmergencyActivity.class);
  
          // FLAG_ACTIVITY_NEW_TASK is needed because we're not in an activity
          // already, without it we crash.
          myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(myIntent);
  </code></pre>
  
  <p>You can see the rest of the code at <a href="http://code.google.com/p/emergencybutton/source/browse" rel="nofollow noreferrer">http://code.google.com/p/emergencybutton/source/browse</a></p>
  
  <p>edit: I tried running the activity differently, but still it doesn't work correctly:</p>
  
  <pre><code>Intent myIntent = new Intent();
  myIntent.setClassName("com.emergency.button", "com.emergency.button.EmergencyActivity");
  </code></pre>