My notification service starts Main activity if my app has been minimised by pressing the home button
<p>My app has a notification service. The problem is when my app has been minimised [by pressing the home button] and notification service fires a notification my main activity gets started on its own. Its really annoying and i need to fix it.</p>

<p>Any one with a probable solution??</p>

<p>I tried using android:launchMode="singleInstance" given as a solution @ <a href="http://stackoverflow.com/questions/4535673/why-does-starting-an-activity-from-a-widget-cause-my-main-activity-to-start-as-we/4540799#4540799">Why does starting an activity from a widget cause my main activity to start as well?</a> but the problem with this solution is that if i try to re-start my app using the "long press home button, which gives the list of recently used app" my app never runs.</p>

<p>In order to re-run it then i have to go to my App's Icon in menu and open it from there.</p>

<p>Is there a way i can solve both these problems?? </p>

<p>Activity that generates notification : </p>

<p>package org.example.com;</p>

<pre><code>import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;

public class ParentActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_copy);

    NotificationManager newNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    final Notification notificationDetails = new Notification(R.drawable.icon,"Downloads available!!",System.currentTimeMillis());
    notificationDetails.flags = Notification.FLAG_AUTO_CANCEL;

    Intent newIntent = new Intent(this,ParentActivity.class);
    newIntent.putExtra("IS_FOREGROUND",1);
    //newIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent newPendingIntent = PendingIntent.getActivity(this, 0, newIntent, 0);

    CharSequence contentTitle = "Downloads Available!!";
    CharSequence contentText  = "Some new Downloads are available, click to enable.";
    int notificationId = 3;

    notificationDetails.setLatestEventInfo(this, contentTitle, contentText, newPendingIntent);
    newNotificationManager.notify(notificationId, notificationDetails);

    finish();

}
}
</code></pre>
