android - App crashes due to leaked window -


my app working fine of sudden crashes , error getting me more crazy. working both on server , on local files. crashes whenver try read file server.

my logcat follows:

error/windowmanager(10324): activity idtech.esdn.map has leaked window com.android.internal.policy.impl.phonewindow$decorview@41838b78 added here         android.view.windowleaked: activity idtech.esdn.map has leaked window com.android.internal.policy.impl.phonewindow$decorview@41838b78 added here         @ android.view.viewrootimpl.<init>(viewrootimpl.java:380)         @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:292)         @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:224)         @ android.view.windowmanagerimpl$compatmodewrapper.addview(windowmanagerimpl.java:149)         @ android.view.window$localwindowmanager.addview(window.java:547)         @ android.app.dialog.show(dialog.java:277)         @ idtech.esdn.map$loadfile.onpreexecute(map.java:64)         @ android.os.asynctask.executeonexecutor(asynctask.java:586)         @ android.os.asynctask.execute(asynctask.java:534)         @ idtech.esdn.map.onactivityresult(map.java:241)         @ android.app.activity.dispatchactivityresult(activity.java:5194)         @ android.app.activitythread.deliverresults(activitythread.java:3180)         @ android.app.activitythread.handlesendresult(activitythread.java:3227)         @ android.app.activitythread.access$1100(activitythread.java:137)         @ android.app.activitythread$h.handlemessage(activitythread.java:1258)         @ android.os.handler.dispatchmessage(handler.java:99)         @ android.os.looper.loop(looper.java:137)         @ android.app.activitythread.main(activitythread.java:4838)         @ java.lang.reflect.method.invokenative(native method)         @ java.lang.reflect.method.invoke(method.java:511)         @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:841)         @ com.android.internal.os.zygoteinit.main(zygoteinit.java:608)         @ dalvik.system.nativestart.main(native method) 

its showing error coming on async task follows:

public class loadfile  extends asynctask<string,string,string> {     progressdialog asycdialog = new progressdialog(map.this);       @override     protected void onpreexecute() {         //set message of dialog          super.onpreexecute();         asycdialog.setmessage("loading file");         asycdialog.setbutton(dialoginterface.button_negative,"cancel",new dialoginterface.onclicklistener() {             @override             public void onclick(dialoginterface dialoginterface, int i) {             }         });         //show dialog        if (!map.this.isfinishing())        {            asycdialog.show();        }     }      protected void onprogressupdate(string ... progress)     {      }      protected string  doinbackground(string ... params)     {         map.this.mglview.loadprojectfile(appfuncs.g_path);         map.this.mglview.requestrender();           return null;     }     protected void onpostexecute(string result)     {         asycdialog.dismiss();          super.onpostexecute(result);        } } 

a window leak occurs in case if preexecute/postexecute runs after activity finished. try using weakreference activity , move dialog creation code oncreatedialog method of activity. however, oncreatedialog deprecated , should move dialogfragment.

private int dialog_id_progress = 1; @override protected dialog oncreatedialog(int id) {     if (id == dialog_id_progress) {         progressdialog pd = new progressdialog(this);         pd.setmessage("loading...");         return pd;     }     return super.oncreatedialog(id); }  private class getdatatask extends asynctask<void, void, void> {     private weakreference<activity> mactivityreference;     getdatatask(activity activity) {         mactivityreference = new weakreference<activity>(activity);     }      @override     protected void onpreexecute() {         super.onpreexecute();         activity activity = mactivityreference.get();         if(activity != null) {             activity.showdialog(dialog_id_progress);         }     }      @override     protected void doinbackground(void... params) {         // todo auto-generated method stub         return null;     }      @override     protected void onpostexecute(void result) {         super.onpostexecute(result);         activity activity = mactivityreference.get();         if(activity != null) {             activity.dismissdialog(dialog_id_progress);         }     } } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -