I'm developing an application which is mainly a webview and will display a JQTouch UI. Two of the 3 views work just fine, however, I have a view which loads another page with a form which does not work at all. This view loads up just fine but when I click the link to go to the form the link just stays highlighted and nothing happens. I have overriden all of the methods in webviewclient and webchromeclient and placed breakpoints within with no luck. None of the hooks catch when I click the links.
The part that truly confounds me is that it works in the phones browser but not in my webview. Is there a setting on webview that I may be missing which would make it act like the phones browser?
Any help or suggestions would be appreciated.
The fix for this was to override onLoadResource as the link was being treated as a resource and not a new page load. I tried calling webView.loadUrl right in the override of loadREsource but that caused an endless loop so I had to write some logic to load the url properly into my webView. This seems a bit hacked but it works.
Related
I have done my research and I haven't found a suitable question for my problem. I got a WebView inside a ScrollView, and once I get the HTML from my service, I call
myWv.loadDataWithBaseURL(null,myHtml,"text/html","utf-8",null);
Nothing special there. The problem I'm having is that, when I run my Application in a 4.4.2 Android tablet, the WebView loads the HTML with the words split in lines, eg:
This
is
my
sentense
And after a second it renders the HTML correctly but the ScrollView's scroll is as big as the number of lines it rendered before loading the HTML correctly. I have tested in 3 different smartphones and everything is fine, only in the tablet it seems to happen, probably due to some performance issue since my HTML is huge.
Does any of you have have had this problem before and knows how to solve it? Thanks in advance.
Extend WebViewClient. And in your custom WebViewClient overload the method onPageFinished.
#Override
public void onPageFinished(WebView view, String url) {
// If you create a listener, here you can trigger it
// you can show the webview here as it will be already measured.
}
If you show the webview when the page is already entirely loaded there won't be any ugly animation.
I have a list and when I click on one item of the list, one HTML page is called like that:
webView.loadDataWithBaseURL("file:///android_asset/", content, "text/html", "utf-8", "about:blank");
Inside this webview, there is HTML5 video (I'm using this library https://github.com/cprcrack/VideoEnabledWebView). When I enter in full screen mode with the video, then return to the list and click on another item to load an HTML page, this page takes too long to load (like minutes).
This only happens on some 4.4.2 devices, on the emulator it loads quickly.
My hardwareAccelerated is enabled.
I found out that if I rotate the screen, the second page loads quickly. But I tried to reload the page ou setting to clear the view, but it didn't work.
Does anyone has any idea why this happens?
I'm also getting this error:
[ERROR:in_process_view_renderer.cc(193)] Failed to request GL process. Deadlock likely: 0
If your working on web view i would suggest to look on crosswalk and chromium. Its best way to bring in hardware acceleration into the project.
In android app I have webView page that use jquery plugin for lazyload. In mobile browser it work fine but not in webView. After debug I find out that even this doesnt trigger alert.
$(window).scroll(function() {
alert("Scrolled");
}
Does there is special way to handle scroll events in webView?
PS For lazy load i use this plugin http://www.appelsiini.net/projects/lazyload
window.onscroll works with the WebView. Some things to check:
you have placed the WebView in a ScollView and/or set it's height to wrap_contents,
the contents of the WebView is too short to scroll,
you haven't implemented the WebChromeClient.onJsAlert callback to handle alert. By default the WebView doesn't display a popup.
I have a WebView I'm loading in an activity in order to have it preloaded so that it pops up immediately in a different Activity (launched from the first).
The problem is that in order to instantiate a WebView, I have to pass in a Context, in this case it's the first mentioned above.
So it works great, and the second Activity shows the WebView just fine. The problem is that if I click a <select> dropdown in the WebView, its selector dialog shows up UNDER the WebView. It feels like the select doesn't work at all until you hit the back button and briefly see the selection dialog just before you return to the parent activity.
It seems as though when I append the WebView to the layout in the second activity, it's modals get attached to that activity's window, but the WebView itself is attached to the parent activity's window, so it shows in a higher point in the hierarchy.
How can I possibly change the Context of the WebView after it's been instantiated?
This is a very difficult problem to solve -- I have to create the WebViews before the activity is started, but I also need the selection dialogs to work.
Please if anyone can give me some insights here I'd greatly appreciate it.
This is for an SDK project, so I will not have access to the parent activity. Also, saveState isn't working, because the bulk of what is shown in the WebView is generated by JavaScript, and the full DOM stack doesn't transfer.
You can try to create the WebView with a MutableContextWrapper:
MutableContextWrapper mMutableContext=new MutableContextWrapper(context);
WebView mWebView=new WebView(mMutableContext);
and later on you could do
mMutableContext.setBaseContext(newcontext);
But ...
WebView is a very complex component that will probably be using the passed context to create other objects like Handlers. WebView probably uses those handlers to post stuff to the original UI thread, so at the end you'll probably have a View with a mix of contexts, you know, a double memory leak (if it ever works properly)
Webview spans at least 1 thread "webcore" that is where the action happens and is also in constant communication with the original UI thread with ... handlers? through the original context? who knows!
There are even 2 different webview engines: Kitkat is chromium-based while jelly bean and previous versions use AOSP/WebView. So you have an additional breaking point.
The reasons you state are not strong enough imho. WebView is not that slow. If the app you load is, try to optimize it. There are a lot of things you can do for that, like loading the HTML & graphics from internal assets.
In my App (it's browser) I have the same problem. I don't like to load WebView every time when user back to App. And I've solved this problem partially. I've overridden onBackPressed() on my HomeActivity and use moveTaskToBack(true) instead of super.onBackPressed(). So when user use system back on HomeActivity it does't destroy Activity and all views. It just minimize the App. Visually it's the same behavior but if user try to run App by launch icon, all views already loaded. I know it's temporary solution and all views can be destroyed by system any time but it gives quite good result. And covers a lot of cases for me.
I am working on a webview with local html file as source.
I am trying to copy a Webview on to another webview.
If I do this.
WebView1.loadUrl(webView2.getUrl());
I works, but it is same as loading the webview again,which i dont want. If I do this
WebView1=WebView2;
It doesn't copy. The content of WebView1 doesn't change. Am I doing anything wrong.
You'll have to remove the current WebView from your Layout (by calling removeView(WebView1) on it's container) and then add the new WebView to it (addView(WebView2) on the same container). Obviously you'll have to take care that it gets inserted at the right place again. Easiest way would be to just wrap a FrameLayout around it and call said methods on it.
Can't promise you that this will work though, since I don't know how WebView behaves offscreen.