场景:在我的应用程序中,当我单击按钮时,它会打开带有 WebView 的对话框,加载一些数据(这涉及在本地复制、编辑和加载 HTML 文件)。WebView 应显示本地创建的 HTML 文件。
发生了什么:对话框需要很长时间才能打开。它至少等待文件复制和编辑部分。当 WebView 开始加载 HTML 文件时,该对话框打开。
我尝试过的: 我尝试在主线程中调用这些:
url = prepareLocalHtmlFile(dataKey); //Copy and edit html file and returns its path in local dir
webView.loadUrl(url); //Show the html file in WebView
也在单独的线程中尝试过:
Thread mThread = new Thread() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
url = prepareLocalHtmlFile(dataKey); //Copy and edit html file and returns its path in local dir
webView.loadUrl(url); //Show the html file in WebView
}
});
}
};
mThread.start();
我想要什么:一旦我按下按钮,对话框应该立即打开,然后所有耗时的操作都应该发生(复制、编辑、在 webView 中加载 HTML)。请建议如何实现它。