How to avoid multiple instance of activity starting from service
<p>I am working in a <strong>service</strong>, on device boot my service starts along with application.
Now if service finds some restricted apps launched, it backgrounds my application, shows home, kill app, and start again activity to foreground. But it is creating multiple instances when starting activity <strong>on boot</strong>.</p>

<p>I want to start previously launched activity every time if it exists, I am using the following code:</p>

<pre><code>    //activity to background    
    Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(startMain);

    //killing restricted app    
    Appmgr.killBackgroundProcesses(RunningP.processName);

    //again start activity      
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ComponentName cn = new ComponentName(this, TaxiPlexer.class);
    intent.setComponent(cn);
    startActivity(intent);
</code></pre>

<p>I have used FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY and others but they are giving me force close error. Above code only creates multiple instances <strong>ON BOOT</strong></p>
