android.view.windowleaked error showing me in dialog.dismiss() -



android.view.windowleaked error showing me in dialog.dismiss() -

shows error in dialog.dismiss() called in onpostexecute().dialog.show() called in onpreexecute()

this task called login activity.

public class signintask extends asynctask<string, string, string>{ progressdialog dialog; string responsestring; signinactivity appcontext; string url; string pageurl="signin?"; string emailparameter="email="; string passwordparameter="pass="; string user_device="android"; //string username,password; signinmodel signinmodel; public signintask(signinactivity c,signinmodel model) { appcontext=c; signinmodel = model; url=utility.baseurl+pageurl+emailparameter+signinmodel.getemail()+"&"+passwordparameter+signinmodel.getpassword()+"&"+user_device; //url="http://bioscopebd.com/mobileappand/signin"; log.i("url", url); } protected void onpreexecute(){ dialog = new progressdialog(appcontext); dialog.setprogressstyle(progressdialog.style_spinner); dialog.setmessage("login..."); dialog.show(); super.onpreexecute(); } string filterresponsestring(string r) { homecoming r.replace("\r\n", ""); } @override protected string doinbackground(string... uri) { httpclient httpclient = new defaulthttpclient(); httpresponse response; seek { response = httpclient.execute(new httpget(url)); statusline statusline = response.getstatusline(); if(statusline.getstatuscode() == httpstatus.sc_ok){ bytearrayoutputstream out = new bytearrayoutputstream(); response.getentity().writeto(out); out.close(); responsestring = out.tostring(); responsestring=filterresponsestring(responsestring); } else { //closes connection. response.getentity().getcontent().close(); utility.showmessage(appcontext, "cannot connect internet"); } } grab (exception e) { //todo handle problems.. } homecoming responsestring; } @override protected void onpostexecute(string result) { dialog.dismiss(); if(responsestring!=null) { log.i("response string", responsestring); //appcontext.signindataloaded(responsestring); jsonobject jobj; //signinmodel signin = new signinmodel(); seek { jobj = new jsonobject(responsestring); signinmodel.setstatus( jobj.getboolean("status") ); signinmodel.setuserid( jobj.getstring("user_id") ); appcontext.signindataloaded(signinmodel); } grab (jsonexception e) { // todo auto-generated grab block e.printstacktrace(); } }else { log.i("response string", "null"); } super.onpostexecute(result); //do response.. }

i haven't face exception before details nice.

logcat 11-13 23:27:39.670: e/windowmanager(826): android.view.windowleaked: activity com.bioscope.main.signinactivity has leaked window com.android.internal.policy.impl.phonewindow$decorview{b2a14910 v.e..... r......d 0,0-684,192} added here 11-13 23:27:39.670: e/windowmanager(826): @ android.view.viewrootimpl.<init>(viewrootimpl.java:348) 11-13 23:27:39.670: e/windowmanager(826): @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:248) 11-13 23:27:39.670: e/windowmanager(826): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) 11-13 23:27:39.670: e/windowmanager(826): @ android.app.dialog.show(dialog.java:286) 11-13 23:27:39.670: e/windowmanager(826): @ com.bioscope.server.signintask.onpreexecute(signintask.java:55) 11-13 23:27:39.670: e/windowmanager(826): @ android.os.asynctask.executeonexecutor(asynctask.java:587) 11-13 23:27:39.670: e/windowmanager(826): @ android.os.asynctask.execute(asynctask.java:535) 11-13 23:27:39.670: e/windowmanager(826): @ com.bioscope.main.signinactivity$2.onclick(signinactivity.java:91) 11-13 23:27:39.670: e/windowmanager(826): @ android.view.view.performclick(view.java:4438) 11-13 23:27:39.670: e/windowmanager(826): @ android.view.view$performclick.run(view.java:18422) 11-13 23:27:39.670: e/windowmanager(826): @ android.os.handler.handlecallback(handler.java:733) 11-13 23:27:39.670: e/windowmanager(826): @ android.os.handler.dispatchmessage(handler.java:95) 11-13 23:27:39.670: e/windowmanager(826): @ android.os.looper.loop(looper.java:136) 11-13 23:27:39.670: e/windowmanager(826): @ android.app.activitythread.main(activitythread.java:5017) 11-13 23:27:39.670: e/windowmanager(826): @ java.lang.reflect.method.invokenative(native method) 11-13 23:27:39.670: e/windowmanager(826): @ java.lang.reflect.method.invoke(method.java:515) 11-13 23:27:39.670: e/windowmanager(826): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 11-13 23:27:39.670: e/windowmanager(826): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 11-13 23:27:39.670: e/windowmanager(826): @ dalvik.system.nativestart.main(native method) 11-13 23:27:41.190: d/androidruntime(826): shutting downwards vm 11-13 23:27:41.190: w/dalvikvm(826): threadid=1: thread exiting uncaught exception (group=0xb1a24ba8) 11-13 23:27:41.210: e/androidruntime(826): fatal exception: main 11-13 23:27:41.210: e/androidruntime(826): process: com.bioscope, pid: 826 11-13 23:27:41.210: e/androidruntime(826): java.lang.illegalargumentexception: view=com.android.internal.policy.impl.phonewindow$decorview{b2a14910 v.e..... r......d 0,0-684,192} not attached window manager 11-13 23:27:41.210: e/androidruntime(826): @ android.view.windowmanagerglobal.findviewlocked(windowmanagerglobal.java:370) 11-13 23:27:41.210: e/androidruntime(826): @ android.view.windowmanagerglobal.removeview(windowmanagerglobal.java:299) 11-13 23:27:41.210: e/androidruntime(826): @ android.view.windowmanagerimpl.removeviewimmediate(windowmanagerimpl.java:84) 11-13 23:27:41.210: e/androidruntime(826): @ android.app.dialog.dismissdialog(dialog.java:329) 11-13 23:27:41.210: e/androidruntime(826): @ android.app.dialog.dismiss(dialog.java:312) 11-13 23:27:41.210: e/androidruntime(826): @ com.bioscope.server.signintask.onpostexecute(signintask.java:108) 11-13 23:27:41.210: e/androidruntime(826): @ com.bioscope.server.signintask.onpostexecute(signintask.java:1) 11-13 23:27:41.210: e/androidruntime(826): @ android.os.asynctask.finish(asynctask.java:632) 11-13 23:27:41.210: e/androidruntime(826): @ android.os.asynctask.access$600(asynctask.java:177) 11-13 23:27:41.210: e/androidruntime(826): @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:645) 11-13 23:27:41.210: e/androidruntime(826): @ android.os.handler.dispatchmessage(handler.java:102) 11-13 23:27:41.210: e/androidruntime(826): @ android.os.looper.loop(looper.java:136) 11-13 23:27:41.210: e/androidruntime(826): @ android.app.activitythread.main(activitythread.java:5017) 11-13 23:27:41.210: e/androidruntime(826): @ java.lang.reflect.method.invokenative(native method) 11-13 23:27:41.210: e/androidruntime(826): @ java.lang.reflect.method.invoke(method.java:515) 11-13 23:27:41.210: e/androidruntime(826): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 11-13 23:27:41.210: e/androidruntime(826): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 11-13 23:27:41.210: e/androidruntime(826): @ dalvik.system.nativestart.main(native method) activity class

signin button click portion

signin.setonclicklistener(new view.onclicklistener() {

@override public void onclick(view v) { signinmodel signinmodel = new signinmodel(); string email = emailedittext.gettext().tostring().trim(); string password = passwordedittext.gettext().tostring().trim(); if(formhelper.isvalidemail(email) ) signinmodel.setemail(email); signinmodel.setpassword(password); //utility.showmessage(signinactivity.this, signinmodel.getemail()+" "+signinmodel.getpassword()); new signintask(signinactivity.this,signinmodel).execute(); intent i=new intent(signinactivity.this, homeactivity.class); i.putextra("user_check",1 ); startactivity(i); finish(); } });

the mutual reason error message activity dialog shown on has been closed prior dismissing dialog - causing leaked window.

in scenario, introducing asynctask, there might possibility activity executed task has been terminated prematurely. example: back-key pressed user, no-history attribute in manifest activity or due other reasons.

there might possibility finishing activity right-after executing async task. in case, dialog cannot survive parent window terminated.

for safeguard, suggest include dialog.setcancelable(false); dialog. block user finishing activity. 1 time dialog dismissed after reaching onpostexecute, user allowed finish activity. or create sure not finishing activity async task reached onpostexecute.

or alternate take dialog out asynctask , attach activity's life cycle may dismiss dialog in ondestroy on activity.

android

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -