MainActivity
我在mProgressDialog.show()上遇到错误;线。所有这些都在AsyncTask中,请帮帮我。我还在Aysnctask的背景方法上执行一些上传操作
@Override
protected void onPreExecute() {
res = null;
count = 0;
//mProgressDialog = ProgressDialog.show(Create_NewsFeed.this, "","Uploading image");
mProgressDialog = new ProgressDialog(Create_NewsFeed.this);
mProgressDialog.setMessage("Posting.. please wait...");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setMax(100);
mProgressDialog.show();
try {
// creates a unique boundary based on time stamp
boundary = "===" + System.currentTimeMillis() + "===";
URL url = new URL(requestURL);
httpConn = (HttpURLConnection) url.openConnection();
httpConn.setUseCaches(false);
httpConn.setDoOutput(true); // indicates POST method
httpConn.setDoInput(true);
httpConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
httpConn.setRequestProperty("User-Agent", "CodeJava Agent");
httpConn.setRequestProperty("Test", "Bonjour");
outputStream = httpConn.getOutputStream();
writer = new PrintWriter(new OutputStreamWriter(outputStream, charset),true);
writer.append("User-Agent" + ": " + "CodeJava").append(LINE_FEED);
writer.flush();
writer.append("Test-Header" + ": " + "Header-Value").append(LINE_FEED);
writer.flush();
} catch (Exception e) {
//...
}
}
这是我的错误日志。请检查一下。
10-08 12:03:00.185 27823-27823/fourever.textile E/WindowManager﹕ Activity fourever.textile.mainclasses.Create_NewsFeed has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@422e43b0 that was originally added here
android.view.WindowLeaked: Activity fourever.textile.mainclasses.Create_NewsFeed has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@422e43b0 that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:409)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:322)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:234)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:153)
at android.view.Window$LocalWindowManager.addView(Window.java:559)
at android.app.Dialog.show(Dialog.java:277)
at fourever.textile.mainclasses.Create_NewsFeed$ServiceSync$1.run(Create_NewsFeed.java:440)
at android.app.Activity.runOnUiThread(Activity.java:4766)
at fourever.textile.mainclasses.Create_NewsFeed$ServiceSync.onPreExecute(Create_NewsFeed.java:437)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
at android.os.AsyncTask.execute(AsyncTask.java:534)
at fourever.textile.mainclasses.Create_NewsFeed$1$1.run(Create_NewsFeed.java:131)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
像这样调用你的api / asynctask,
this.runOnUiThread(new Runnable() {
@Override
public void run() {
//api calls .. or use async task here
}
});