Issue
I am using Webview
in an Android activity (say Activity B) like this
webview = new WebView(this);
webview.setWebViewClient(new WebViewClient());
setContentView(webview);
webview.loadUrl("http://mywebpage");
So, the webview opens a webpage in the activity, and the expected functionality is that user can browse different web pages following the links in the webview. (The website is of the mobile application, or in other words, is in my control).
Now, after the user is done checking out the webpages, how do I take the user to another activity? (if it helps the activity - activity A - will be the same from where the activity B containing the webview was called).
So can I, from the webview decide to finish the current activity (B) so the user is back to activity A? Or if possible, directly start another activity which could be activity A or some other activity C based on some event on the webpage?
Or will I need to provide a button outside the Webview on Activity B from which I can handle the flow?
Or there is a better approach?
Solution
What I have done in the past is provide a close button below the webview in the webview activity (in your case Activity B). If you invoke Activity B from Activity A using startActivityForResult, then the control will return to Activity A once Activity B closes (to be more specific, once Activity B closes, onActivityResult is called in Activity A).
In conjunction with the above, another thing you can try if you have a defined browsing process starting from page A and going to Page X is that you can auto-close Activity B when Page X is reached. Extend WebViewClient
, listen to the onPageFinished
event to get the current page URL and close the activity if the current URL matches the termination URL.
Answered By - Theo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.