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

我目前正在执行一个异步任务,以将一些数据发布到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)

如何解决该问题?非常感谢

解决方法:

只需确保在显示对话框之前没有完成SharePicForm活动即可.错误显示显示对话框时,您的SharePicForm活动不存在.也许它已经退出了.

上一篇:android-在ListFragment中显示ProgressDialog


下一篇:java-无法在某些设备上尚未调用Looper.prepare()的线程内创建处理程序