Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser callbacks and Android Activity stack madness

Tags:

android

oauth

I'm struggling to get a specific behavior for OAuth authorization using the ubiquitous callback with custom scheme->intent_filter technique.

My app registers for SEND actions and, when called, starts a service which, in turn, checks if the user is already authorized and, if not, spawns an activity (OAuthActivity) to request login.

Keep in mind that the foreground activity right before this happens may be anything. The activity then starts a VIEW intent to open the auth page in the browser; the latter invokes the crafted callback (with custom scheme defined in manifest) and wakes the OAuthActivity.

OAuthActivity has, currently, launchMode="singleTask" but this doesn't make a difference from stack perspective (it gets on top when called back).

Is there a way I can clear the activity stack and get back to what the user was doing and not force him push 'back' on the browser activity? (I'll then show a notification when the content was successfully submitted in the background)

Does anyone have any pointers? Thanks for reading through

like image 736
Utaal Avatar asked Jan 24 '12 22:01

Utaal


1 Answers

The activity then starts a VIEW intent to open the auth page in the browser

That's the problem. This works for me: render the oauth web page in a webview you control rather than launching out to the browser app.

The oauth web page, when it calls its callback, will actually be replacing itself in the webview, where your WebViewClient can catch that expected URL, process the results, and finish() the webview (removing it from the activity stack).

like image 94
larham1 Avatar answered Nov 30 '22 18:11

larham1