简体   繁体   中英

How can I give the user an easy way back from a WebKit session in my Android application?

My Android application needs to switch back and forth between client code and WebKit sessions. During certain operations I redirect the user to different web sites that I load via WebKit. I want to give the user an easy way to leave the WebKit session and jump back to my application to do another operation or modify the last on. I don't want to rely on the browser BACK button because that could be a burden on the user if they have done any significant page navigation on a web site and have to back out of the session to my application.

I would like to put up a button or link somewhere the user could click whenever they want to return to my application. Note, I am not asking if I can inject elements into the WebKit session because I'm pretty sure WebKit will not allow that.

Any ideas? Also, any tips on maintaining state information between WebKit launches are welcome. I know about the Activity constructor Bundle parameter, but if there are any subtle nuances I need to watch out for just let me know.

-- roschler

(When you say "WebKit" I assume you mean the default system browser, not the embeddable WebView class.)

It can be done via custom URL schemes. An example custom URl scheme is:

myapp://somedata:someotherdata

you can register your app to be invoked for this scheme:

<activity ....>
    <intent-filter>
        <data android:scheme="myapp"/>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
    </intent-filter>
</activity>

Then in you browser just reference myapp:// as you would with any other http:// url (via button, link, javascript..). You my also add some data after scheme, eg myapp://some:data an you can retreive it in your app via getIntent().getData() .

Note: custom schemes are global - make sure you dont clash with some other app. Best to use the full package name com.mypackage.myapp:// .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM