Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  51] [ 2]  / answers: 1 / hits: 19293  / 13 Years ago, thu, april 28, 2011, 12:00:00

I have WebView which loads some page, when it's finished I apply some javascript magic to mess up with DOM. Everything is fine, page loads and onPageFinished I just call wv.loadUrl(javascript);



But I don't want to see loading process, and how javascript is working, I just need result, so I made my view invisible with wv.setVisibility(View.INVISIBLE); from the start, and make it visible again when everything is done. This is where problem occurs.



This piece of code should make view visible after javascript is finished, but wv.setVisibility(View.VISIBLE) fires before javascript. So for a moment I see page and how it is being changed by javascript. This is just ugly.



  public void onPageFinished (WebView view, String url) {
wv.loadUrl(javascript);
view.getSettings().setLoadsImagesAutomatically(true);
wv.setVisibility(View.VISIBLE);

}


I got that loadUrl works asynchronously, so I tried to make another WebViewClient with just make first view visible method inside onPageFinished, and use it to call JS. But it just keeps crashing with NPE error.



wv2.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished (WebView view, String url) {
wv.setVisibility(View.VISIBLE);
}
});


For now I just added delay after javascript (SystemClock.sleep(5000)), but this is like.. yeah.


More From » android

 Answers
85

Ok, I think I figured it out. We can have callback from the end of javascript that will fire show view - like here or here (with handler, because I wanted to update ui).
But it wont change anything, the problem seems to be in rendering speed. It's just slow. So for now I'll just stick with 1 second delay after firing JS.


[#92500] Wednesday, April 27, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devlin

Total Points: 474
Total Questions: 113
Total Answers: 100

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
devlin questions
Tue, Apr 27, 21, 00:00, 3 Years ago
Sat, Oct 31, 20, 00:00, 4 Years ago
Fri, Aug 28, 20, 00:00, 4 Years ago
;