I have an application that starts up with a login activity, which redirects the user to a browser in order to authenticate to a service (has to be done via the browser, can't use a REST API or curl), and then jumps back to the application with a session ID. Going from the application to the browser is easy, I just launch it like so:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://domain.com/login/?url=appscheme://loggedin&sessionTransfer=window"));
startActivity(intent);
Once the user has logged in, the browser is supposed to jump back to the application (with a session ID) via an intent filter on the destination activity, declared using android.intent.category.BROWSABLE.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="loggedin"
android:scheme="appscheme" />
</intent-filter>
The problem is that instead of resuming execution under the original application instance, it appears to execute everything after the initial login screen under the browser instance. This is bad for a few reasons. First of all, it means that the Recent Apps menu shows everything the user has been doing as happening in the browser, and the main application only shows a login button. Secondly, whenever the app is closed and the browser is opened, the browser tends to reopen the app from the existing tab.
How can I use the browser and then ensure that when the user is finished logging in via the browser, all activity resumes under the original app instance?
EDIT: In case this helps to improve clarity, this is the intended flow, including how each activity is supposed to be listed in the Recent Apps list: MyActivity1 (associated with MyApp) -> Browser -> MyActivity2 (associated with MyApp)
And here's what actually happens: MyActivity1 (associated with MyApp) -> Browser -> MyActivity2 (associated with Browser)
So right now, if a user wanted to go check an email and then come back to my app, they would actually have to select Browser from Recent Apps for it to work.