I have some problem with this code, here you can find a simplified version of the problem.
public class MyActivity extends Activity {
private WebView wv = null;
private CountDownLatch signal = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
wv = (WebView) findViewById(R.id.web);
wv.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
signal.countDown();
开发者_如何学运维 super.onPageFinished(view, url);
}
}
wv.post(new Runnable() {
@Override
public void run() {
wv.loadUrl("file:///android_asset/MySample.html");
}
});
try {
signal.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
ElaborateAll(2);
}
}
In debug the code doesn't reach ElaborateAll(2).
Every help will be apprecited.
What you're doing there is:
- Adding a custom WebViewClient with a CountDownLatch
- Posting a Runnable to the UI thread
- Blocking the UI thread
And that's it, your execution stops there, the Runnable will not be executed and thus you'll never loadUrl(); remove the CountDownLatch and the program will loadUrl() as expected.
精彩评论