java - WindowLeaked exception right when thread finishes and calls dialog.dissmiss(); -
i have tab layout app needs download few files right when starts, in main.java file in oncreate method call:
myprogressdialog = progressdialog.show(controller.this, "please wait...", "doing extreme calculations...", true); downloadfile(name_local, name_server, true);
downloadfile separate thread looks likes this:
protected void downloadfile(final string localfilepath, final string remotefilename, final boolean ascii) { // fire off thread work shouldn't directly in ui thread thread = new thread() { public void run() { logger.setlevel(level.debug); try{ //create client log.info("creating client"); ftp = new filetransferclient(); log.info("setting remote host"); ftp.setremotehost(host); ftp.setusername(username); ftp.setpassword(password); //connect. . .we hope log.info("connecting server " + host); ftp.connect(); ftp.getadvancedftpsettings().setconnectmode(ftpconnectmode.pasv); if(ascii){ ftp.setcontenttype(ftptransfertype.ascii); log.d("ascii", "using ascii"); }else if(!ascii){ log.d("binary", "using binary"); ftp.setcontenttype(ftptransfertype.binary); } ftp.downloadfile(cache + localfilepath , remotefilename); }catch (exception e){ e.printstacktrace(); } mhandler.post(mupdateresults); handler handler=new handler(); handler.post(new runnable(){public void run(){myprogressdialog.dismiss();}}); } }; a.start(); }
in log cat starts download, , finishes sudden gives me this:
02-17 17:27:51.175: error/windowmanager(2523): activity org.ire.toolbox.controller has leaked window com.android.internal.policy.impl.phonewindow$decorview@46eba2f0 added here 02-17 17:27:51.175: error/windowmanager(2523): android.view.windowleaked: activity org.ire.toolbox.controller has leaked window com.android.internal.policy.impl.phonewindow$decorview@46eba2f0 added here
whats going on?! in advance!
the code posted going raise exception in thread.run()
at:
handler handler=new handler();
the reason thread has not called looper.prepare
. saw "force close" prompt , if dig through logs, you'll find like:
error/androidruntime(1161): uncaught handler: thread thread-9 exiting due uncaught exception error/androidruntime(1161): java.lang.runtimeexception: can't create handler inside thread has not called looper.prepare() error/androidruntime(1161): @ android.os.handler.<init>(handler.java:121)
Comments
Post a Comment