hello im makeing a vwe browser app and it have a faw problem and dont know which part of the code i post
bookmark activity when i go to the bookmark activity it opens fine but when i switch back to the webview it reload to the homepage not the last page it was in PS it don't reloads when the screen change Orientation
its kind of slow
open videos like youtube but don't let them go full screen
ourview = (WebView) findViewById(R.id.webView1);
ourview.getSettings().setJavaScriptEnabled(true);
ourview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
ourview.getSettings().setLoadWithOverviewMode(true);
ourview.getSettings().setSupportZoom(true);
ourview.getSettings().setBuiltInZoomControls(true);
ourview.getSettings().getAllowFileAccess();
ourview.getSettings().getAllowFileAccessFromFileURLs();
ourview.getSettings().getJavaScriptCanOpenWindowsAutomatically();
ourview.getSettings().setLoadsImagesAutomatically(true);
ourview.loadUrl("http://www.google.com");
Switching between different activities,will always call onCreate() method.
So since your ourview.loadUrl("http://www.google.com"); is in onCreate() method,
it is called each time when you switch between those activities.
That is why webView reload to homepage when switching between activities.
Related
I have a webview activity that shows my interfaces, but I have to call another activity (non webview).
After the other activity has finished I have to go back to the webview one, but it takes too long to open as it recreates the activity in a intent.
Is there a way to keep the webview activity in the background and just reopen it once the other activity has finished? Any suggestions to make the webview at least load faster?
there
I have a problem with android back key at webapp.
My status is that there is one html5 page.
There is a button at html5 page to call android intend method, so the page is moved to android activity. So far, so good.
The problem is that after pressing back button, android home launcher is shown up.
I wanna go back to html5 again when I press back button.
Can you give me some hint?
You need to override onBackPressed in the Android activity. I think the HTML5 page should still be present when you start this new activity which will come on top of the HTML5 page, so when you finish this activity, you should automatically go back to the HTML5 page.
public void onBackPressed() {
finish();
}
I have a number of different webviews, all in their own activity.
When a menu item is pressed a new activity loads and so does it's webview.
Now clicking between activities reloads each webview, is there a way so that when changing activities the web page doesn't reload and it remembers where the user was?
Thanks
You can use WebView method saveState()/restoreState() and save it to activity onRestore bundle and use saved value in onCreate method if the previous Activity will be destroyed.
You can use similar method which is described here (but used for only configuration change):
http://www.devahead.com/blog/2012/01/preserving-the-state-of-an-android-webview-on-screen-orientation-change/
I've trying for days now to get a solution to show a splash screen while loading a webview.
I've looked around and there are several approaches:
- make activity just to show splash screen, wait a few seconds and then start the webview activity -> this is not a solution since all the loading is again done after splash screen is closed
second approach is something like this:
myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
myWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
findViewById(R.id.webview).setVisibility(View.VISIBLE);
//hide loading image
findViewById(R.id.imageView1).setVisibility(View.GONE);
//show webview
}
});
This works, but again there is a slight appearance of a white screen while transitioning to webview. And also you can't control the timing of your splash screen.
third solution is something that I'd like to make, but (even after few days of searching and trying) don't know how -> show splash screen in one thread, prepare everything for a webview in another and then simply switch to webview.
My question is, can anybody show me where to start with this third solution?
I wanted to try something like this! but I couldn't figure out how to pass webview to another activity and from what I read, this is not even a good idea.
Any suggestion, ideas, pointers? Is there a way to show splash screen, prepare(inflate) webview in another thread and then switch to it after loading url (and everything else) is done?
Thanks!!!
Try to use a WebChromeClient on the Webview. In the WebChromeClient, you have a method onProgressChange.
You can do disappear the splash screen when the onProgressChange tell you that the page are finish to load.
Edit:
You can call in a thread your Url with HttpGet for example and retrieve the response. When you have the response you can load the webview with the loadData(...) method.
I've read multiple similar posts but have not found a working solution for this problem.
I have two activities A and B. Activity B is launched from Activity A (when I click a button in Acitvity A). Activity B loads a url which displays a map.
The problem is that, when I navigate away from Activity B and come back to it, the webview loads the URL again. Is there way to kind of maintain the state of the webview as is so that it does not load the url again.. I've seen posts hinting at onSaveInstanceState but I havent been successful getting this work.
Can someone please post some psedo/sample code?
Thanks in advance!
I've solved this problem using Fragments: Fragments Show/Hide
I could not find a way to maintain the state of webview (so that it does not requery the url) when I navigate away from a webview to another activity and navigate back to the webview - It alway reloads the url.
I found the fragment approach much better. Fragments was introduced in Android Honeycomb but for earlier versions you can you the support package : Comatibility Package