Breaking the task barrier
<p>I have an android app. I added an intent filter to one of my activities, so that if a url is clicked in the browser app, my activity can be launched. Looks like this:</p>

<pre><code>&lt;data android:host="www.mysite.com" android:scheme="http"&gt;&lt;/data&gt;
</code></pre>

<p>this works well. The problem is that every time my activity is launched from the browser, a new instance of the activity is created, inside the browser app's task, instead of recycling any existing instance that may be in the system already.</p>

<p>This is a problem for me because this activity uses a singleton. If I allow more than one instance of this activity to exist, I can get into some weird situations where the two instances are in conflict when they try to share the singleton. I checked and can see that although the activity instances may be in separate tasks, they do share the same singleton instance.</p>

<p>An ideal solution for me would be if I could somehow bring a pre-existing instance of my application to the foreground, and launch or resume the target activity within whatever pre-existing instance of my app happens to be running.</p>

<p>So I tried this:</p>

<ol>
<li>Register above filter to point to dummy activity which is just a catcher.</li>
<li>Dummy activity creates a broadcast intent, and tries to broadcast 'create me' message to system.</li>
<li>Real target activity is set to listen for this broadcast message. Hopefully if there is already an instance of the activity in the system, it will come to the foreground. If no instance yet, that's ok, allow creation in the browser task.</li>
</ol>

<p>Not sure if this makes sense. My basic goal is to limit the activity to one instance in the system. The app is just social media app which has a login state that needs to be preserved. The singleton mentioned above preserves that login state, so I want to have only one around in the system, instead of allowing multiple login instances running around which would be a headache for the user.</p>

<p>Thanks</p>
