enter code here
我试图在我的Android应用程序中放置一个进度对话框,我遇到了一些麻烦。我是Android的新手,所以我遵循这个教程:
http://p-xr.com/android-tutorial-how-to-make-a-progress-dialog/
当我在手机上测试我的应用时,它所做的就是强制关闭。 有人可以帮忙吗? 继承我的.Java活动:
public class XXXXXActivity extends Activity {
private ProgressDialog progressDialog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView myWebView=(WebView)findViewById(R.id.webview);
myWebView.addJavascriptInterface(new JavaScriptInterface(this),"Android");
WebSettings websettings =
myWebView.getSettings();
websettings.setJavaScriptEnabled(true);
myWebView.setWebViewClient(new MyWebViewClient());
myWebView.loadUrl("http://XXXXX.com");
}
private void runDialog(final int seconds)
{
progressDialog = ProgressDialog.show(this, "Please wait...", "Loading...");
new Thread(new Runnable(){
public void run(){
try {
Thread.sleep(seconds * 1000);
progressDialog.dismiss();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
public class JavaScriptInterface {
Context mContext;
/** Instantiate the interface and set the context*/
JavaScriptInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page*/
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
view.loadUrl(url);
if
(Uri.parse(url).getHost().equals("XXXXX.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent=new
Intent (Intent.ACTION_VIEW,Uri.parse(url));
startActivity(intent);
return true;
}
}
logcat的:
[2012-04-13 19:44:55 - XXXXX] ------------------------------
[2012-04-13 19:44:55 - XXXXX] Android Launch!
[2012-04-13 19:44:55 - XXXXX] adb is running normally.
[2012-04-13 19:44:55 - XXXXX] No Launcher activity found!
[2012-04-13 19:44:55 - XXXXX] The launch will only sync the application package on the device!
[2012-04-13 19:44:55 - XXXXX] Performing sync
[2012-04-13 19:44:55 - XXXXX] Automatic Target Mode: Preferred AVD 'MY-PHONE' is not available. Launching new emulator.
[2012-04-13 19:44:55 - XXXXX] Launching a new emulator with Virtual Device 'MY-PHONE'
[2012-04-13 19:45:08 - Emulator] emulator: WARNING: Unable to create sensors port: Unknown error
[2012-04-13 19:45:08 - XXXXX] New emulator found: emulator-5554
[2012-04-13 19:45:08 - XXXXX] Waiting for HOME ('android.process.acore') to be launched...
[2012-04-13 19:46:05 - XXXXX] emulator-5554 disconnected! Cancelling 'sync'!
答案 0 :(得分:0)
我看到一个问题:你在非gui线程中解雇了对话框:
new Thread(new Runnable(){
public void run(){
try {
Thread.sleep(seconds * 1000);
progressDialog.dismiss();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
这段代码很奇怪,我认为你应该重写逻辑。