android webview display is delayed - android

I got an Acivity holding a WebView displayed on the screen right when it get turned on. The WebView itself is already loaded before. I expect the WebView to be displayed with the rest of the Activity, but instead it is delayed by half a second, so I got a big hole in my layout for this half second.
This happen only the first time the view is displayed after been created.
I do not want the activity to be visible while the WebView isn't, but I cannot find anything telling me when the WebView is avalaible. I tried with getDrawingRect and such, but their values are still been changed before the WebView is visible.
Is it possible to know exactly when a WebView is displayed, or even to erase that delay?
Thanks for your help.

Related

Is it possible to change the context of a WebView after it has been instantiated?

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.

Stop WebView rendering until the page is fully-loaded

I'm working on an app that is using WebView. Unfortunately, when user clicks a link, when the page is loading, the whole WebView area "blinks" until its loading is complete. There's also 1 more problem with it - I'm using a JavaScript that reverses colors of the page at the end of its loading - so until it's fully-loaded, the colors are normal, so again - blinking.
So, what I wannna do is "stop" rendering of the WebView, until the page is completely loaded - then, resume the rendering, so it won't blink. How to do that?
Note: I don't want to modify the webpage to achieve what I want. I have to modify WebView behavior.
And one more note, because it's maybe not clear: by "stop rendering" I mean "display currently rendered page continually until the new one is fully loaded" :)
First make your layout background color white then make the WebView invisible.
after this use AsyncTask then put your webview loading in doInBackground and when it's finished in onPostExecute make your webview visible.
so the user will see the white layout first then the visible webview after fully loaded in postexcute
sorry if my english not good
You could implement a custom WebView, and override it's invalidate() method to do nothing until the page is fully loaded.

How to show loading icon in webview when we flip throug webviews in android

Actually my app hase 3 webviews and we can flip through it. I had added a loading progress bar on each webview. Now when i start the app, first web view loads. I am not able to flip the views as loading symbol is in foreground. My requirement is, webview have to show loading symbol until it loads as well as it can be flipped to other webviews which again have loading symbol.
I am tired of trying everything but not able to do it. Please anyone have any solution.
Thanks in advance....
We can't do anyting when loading symol comes.we have to cancel it by back button for doing anything else. I had solved this by creating a progress bar in XML and doing a logic for making it visible and invisible according to requirement.

WebView, Splash Screen and performance

I've got WebView within an Activity that loads content from the network. When the WebView starts loading I launch another activity to act as a Splash Screen that I hide when the WebView is done loading.
I found out when testing that the same web page takes longer to load when I add a splash screen than when I don't. So I assume there's a network thread whose priority drops when the activity containing the WebView goes to the background. How do I control that thread to keep the WebView fast?
I found the setRenderPriority method of the WebSettings class, I'm not sure what it does and I don't know what is the "Render thread" it talks about. I tried :
getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
but it didn't have any effect on the loading time.
Thanks to anyone who can help me out.
I'm not directly answering your question, but rather suggesting an alternative... starting another activity to simply provide a splash screen could be rather expensive. Instead, you might consider extending the layout that contains your WebView to place a RelativeLayout at the WebView's level, and make your WebView a child of that layout. Additionally, you can place an ImageView (or whatever you need for your splash) within the same RelativeLayout, and you can set its visibility to invisible when you don't want it displayed.

Getting blank screen when switching between activities

I am working on an app , where I am switching between two activities. When control is inside onStart of second activity , there is screen drawing and processing logic being handled.Because of this , when switching between the two activities happens, there is a blank screen that comes up.
Along with this , i also need to render a live video feed in background of my activities/app
What could be the best way to deal with this?
TIA
If you're getting a blank screen it could be because your activity is setting a new contentview but it hasn't been processed properly. Does it ever load completely? If it's just that it's black at the beginning and then renders. Try setting the contentview at the end of your switching in onCreate. This will make it remain on the first activity and avoiding switching views on till everything is loaded.
With regards your second question. Is the live video feed from the Camera?
If it is, set the camera view in the background, make a transparent LinearLayout (or whatever your layout is) over it and then put your various views there.
Your question doesn't have enough specific information to get an accurate idea as to what you're talking about, if my answer doesn't address your problem please respond with elaboration and some code! :-)

Categories

Resources