0

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.

  • See if this helps http://stackoverflow.com/questions/151777/saving-activity-state-in-android – CoderP Apr 07 '14 at 06:50
  • That's not exactly relevant to my problem. The intended flow is: MyApp starts at MyActivity1. It goes from MyActivity1 -> Browser -> MyActivity2. Right now, it gets to MyActivity2, but for some reason once it gets there, MyActivity2 becomes associated with the Browser instead of with MyApp. All the functionality is fine, but the hierarchy of which activity belongs to what gets completely messed up. – Stanley Ayzenberg Apr 08 '14 at 19:39

1 Answers1

0

Turned out that someone asked a similar question here: Starting a new Android Activity in different task

To summarize my solution, I moved the intent-filter to the login activity and declared android:launchMode="singleTask". That way, the browser reopens the login activity and consistently runs onNewIntent(), where I repackage the browser data into a new intent and open the destination activity as intended. A little convoluted, but it works!

Community
  • 1
  • 1