Just make sure that you are not finishing your SharePicForm
activity before showing dialog. Error shows that your SharePicForm
activity does not exist while showing dialog. Or may be it's already exited.
Error exception when show the progress dialog in the async task
-
13-10-2022 - |
Pregunta
I am currently work on an async task to post some data to the API , the problem is it will throw an exception when I was working with the progress dialog. The async task is named "APIhandler" that will handle several type of case.
Here is the constructor
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));
}
}
Here is the onpostexecute
@Override
protected void onPostExecute(JSONObject result) {
if (pd != null && pd.isShowing())
pd.dismiss();
}
Here is the way to call APIhandler
new APIHandler(ctx,tracker,"login").execute(ctx,session.getAccessToken());
The error code (notice that it is fail at the 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)
How to fix the problem ? Thanks a lot
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow