3
我目前正在處理異步任務以將一些數據發佈到API,問題是當我使用進度對話框時,它會引發異常。異步任務被命名爲「APIhandler」,它將處理幾種類型的情況。當在異步任務中顯示進度對話框時出現錯誤異常
這裏是構造
public APIHandler(Context _ctx,EasyTracker _tracker,String _formType) {
this.ctx = _ctx;
this.tracker = _tracker;
this.formType = _formType;
SharedPreferences prefs = ctx.getSharedPreferences("userInfo", 0);
token = prefs.getString("token","");
memId = prefs.getString("memId","");
if (formType.equals("uploadImg")) {
pd = ProgressDialog.show(ctx, ctx.getResources().getString(R.string.sys_info),ctx.getResources().getString(R.string.publishing));
} else {
pd = ProgressDialog.show(ctx, ctx.getResources().getString(R.string.sys_info),ctx.getResources().getString(R.string.loading));
}
}
這裏是onpostexecute
@Override
protected void onPostExecute(JSONObject result) {
if (pd != null && pd.isShowing())
pd.dismiss();
}
這裏是調用APIhandler
new APIHandler(ctx,tracker,"login").execute(ctx,session.getAccessToken());
錯誤代碼(注意,這是失敗的方式dialog.show)
02-18 14:17:17.942: E/WindowManager(440): Activity com.project.hkseven.Activity.SharePicForm has leaked window [email protected] that was originally added here
02-18 14:17:17.942: E/WindowManager(440): android.view.WindowLeaked: Activity com.project.hkseven.Activity.SharePicForm has leaked window [email protected] that was originally added here
02-18 14:17:17.942: E/WindowManager(440): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:439)
02-18 14:17:17.942: E/WindowManager(440): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:307)
02-18 14:17:17.942: E/WindowManager(440): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:228)
02-18 14:17:17.942: E/WindowManager(440): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:153)
02-18 14:17:17.942: E/WindowManager(440): at android.view.Window$LocalWindowManager.addView(Window.java:586)
02-18 14:17:17.942: E/WindowManager(440): at android.app.Dialog.show(Dialog.java:277)
02-18 14:17:17.942: E/WindowManager(440): at android.app.ProgressDialog.show(ProgressDialog.java:116)
02-18 14:17:17.942: E/WindowManager(440): at android.app.ProgressDialog.show(ProgressDialog.java:99)
02-18 14:17:17.942: E/WindowManager(440): at android.app.ProgressDialog.show(ProgressDialog.java:94)
02-18 14:17:17.942: E/WindowManager(440): at com.project.hkseven.Utility.APIHandler.<init>(APIHandler.java:62)
02-18 14:17:17.942: E/WindowManager(440): at com.project.hkseven.Activity.SharePicForm$4.onCompleted(SharePicForm.java:282)
02-18 14:17:17.942: E/WindowManager(440): at com.facebook.Request$4.run(Request.java:1669)
02-18 14:17:17.942: E/WindowManager(440): at android.os.Handler.handleCallback(Handler.java:615)
02-18 14:17:17.942: E/WindowManager(440): at android.os.Handler.dispatchMessage(Handler.java:92)
02-18 14:17:17.942: E/WindowManager(440): at android.os.Looper.loop(Looper.java:137)
02-18 14:17:17.942: E/WindowManager(440): at android.app.ActivityThread.main(ActivityThread.java:4882)
02-18 14:17:17.942: E/WindowManager(440): at java.lang.reflect.Method.invokeNative(Native Method)
02-18 14:17:17.942: E/WindowManager(440): at java.lang.reflect.Method.invoke(Method.java:511)
02-18 14:17:17.942: E/WindowManager(440): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
02-18 14:17:17.942: E/WindowManager(440): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
02-18 14:17:17.942: E/WindowManager(440): at dalvik.system.NativeStart.main(Native Method)
如何解決問題?非常感謝
試用pd.cancel(); –
很遺憾地說,但是你發佈的日誌是因爲可能發生的其他異常。請在窗口泄漏錯誤之前閱讀整個日誌,m確定您會得到實際錯誤 –
您是否在顯示對話框後完成活動SharePicForm? – Anuj