在异步任务中显示进度对话框时出现错误异常

时间:2014-02-18 06:26:30

标签: android asynchronous android-asynctask progressdialog

我目前正在处理异步任务以将一些数据发布到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 com.android.internal.policy.impl.PhoneWindow$DecorView@4231c268 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 com.android.internal.policy.impl.PhoneWindow$DecorView@4231c268 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)

如何解决问题?非常感谢

1 个答案:

答案 0 :(得分:3)

在显示对话框之前,请确保您没有完成SharePicForm活动。错误显示在显示对话框时您的SharePicForm活动不存在。或者可能已经退出。