android - Alert Dialog Box Leaked Error -
i create 1 alert box in android application.but first time shows correctly.in second or third time goes unexpectedly closed,please me.
log cat error
03-20 05:55:27.865: e/androidruntime(4793): caused by: java.lang.illegalstateexception: cannot perform operation because connection pool has been closed. 03-20 05:55:31.055: e/windowmanager(4793): activity com.caprabo.mst.mobpaz.cardapp.activities.oldreceipts has leaked window com.android.internal.policy.impl.phonewindow$decorview{418e4990 v.e..... r.....id 0,0-388,198} added here 03-20 05:55:31.055: e/windowmanager(4793): android.view.windowleaked: activity com.caprabo.mst.mobpaz.cardapp.activities.oldreceipts has leaked window com.android.internal.policy.impl.phonewindow$decorview{418e4990 v.e..... r.....id 0,0-388,198} added here 03-20 05:55:31.055: e/windowmanager(4793): @ android.view.viewrootimpl.<init>(viewrootimpl.java:345) 03-20 05:55:31.055: e/windowmanager(4793): @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:239) 03-20 05:55:31.055: e/windowmanager(4793): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) 03-20 05:55:31.055: e/windowmanager(4793): @ android.app.dialog.show(dialog.java:281) 03-20 05:55:31.055: e/windowmanager(4793): @ com.caprabo.mst.mobpaz.cardapp.activities.oldreceipts.alerter(oldreceipts.java:1332) 03-20 05:55:31.055: e/windowmanager(4793): @ com.caprabo.mst.mobpaz.cardapp.activities.oldreceipts$range_search_result.onpostexecute(oldreceipts.java:1256) 03-20 05:55:31.055: e/windowmanager(4793): @ com.caprabo.mst.mobpaz.cardapp.activities.oldreceipts$range_search_result.onpostexecute(oldreceipts.java:1) 03-20 05:55:31.055: e/windowmanager(4793): @ android.os.asynctask.finish(asynctask.java:631) 03-20 05:55:31.055: e/windowmanager(4793): @ android.os.asynctask.access$600(asynctask.java:177) 03-20 05:55:31.055: e/windowmanager(4793): @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:644) 03-20 05:55:31.055: e/windowmanager(4793): @ android.os.handler.dispatchmessage(handler.java:99) 03-20 05:55:31.055: e/windowmanager(4793): @ android.os.looper.loop(looper.java:137)
code
private class search_result extends asynctask<void,string,integer> { string data; webservice wsobj; commonfunctions cfobj; alertbox abobj; encryption enobj; jsonobject jsobj; string result=""; string encrypted_device_id; progressdialog dialog; int final_flag=0; @override protected integer doinbackground(void... params) { if(cfobj.isconnectingtointernet()) { try { /*jsobj.put("deviceid",encrypted_device_id); jsobj.put("date",extras.getstring("date"));*/ data=urlencoder.encode("deviceid","utf-8") + "=" + urlencoder.encode(encrypted_device_id,"utf-8"); data+="&" + urlencoder.encode("date","utf-8") + "=" + urlencoder.encode(extras.getstring("date"),"utf-8"); result=wsobj.getwebdata(connector.search_by_date_page, data); system.out.println("date result"+result); if(result==null||result=="") { final_flag=ecobj.server_response_no_response_error; } } catch (exception e) { final_flag=ecobj.server_response_no_response_error; } if(final_flag!=ecobj.server_response_no_response_error) { publishprogress(getresources().getstring(r.string.populating_list)); try { if(result!=null && result!="[]"&&result.comparetoignorecase("[]")!=0) { jsonarray mainarray=new jsonarray(result); jsonobject obj=mainarray.getjsonobject(0); int flag=obj.getint("flag"); if(flag==0) { system.out.println("test6 search"); final_flag=ecobj.no_data_available_code; } else { jsonarray jsonarr1=mainarray.getjsonarray(1); string date[]=new string[jsonarr1.length()]; string newdate[]=new string[jsonarr1.length()]; string time[]=new string[jsonarr1.length()]; string elpoints[]=new string[jsonarr1.length()]; string amount[]=new string[jsonarr1.length()]; string transaction_id[]=new string[jsonarr1.length()]; integer transaction_type[]=new integer[jsonarr1.length()]; for(int i=0;i<jsonarr1.length();i++) { jsonobject json_data=jsonarr1.getjsonobject(i); date[i]=json_data.getstring("date"); //calling function date format newdate[i]=cfobj.converdateformate(date[i]); time[i]=cfobj.convertimeformat(date[i]); elpoints[i]=json_data.getstring("earnedpoints"); amount[i]=json_data.getstring("amount"); transaction_id[i]=json_data.getstring("transactionid"); transaction_type[i]=integer.parseint(json_data.getstring("trantype")); aldate.add(newdate[i]); alamount.add(amount[i]); altransaction_type.add(transaction_type[i]); if(transaction_type[i]==1) { transaction_id[i]="-"; } altransactionid.add(transaction_id[i]); key_holder.putstring("date"+i,newdate[i]); key_holder.putstring("time"+i,time[i]); //only ccd needs null. other put elpoints[i] instead of "-" key_holder.putstring("elpoints"+i,"-"); key_holder.putstring("amount"+i,amount[i]); key_holder.putstring("transaction_id"+i,transaction_id[i]); key_holder.putint("trantype"+i,transaction_type[i]); } final_flag=ecobj.success_code; } } else { system.out.println("test3 search"); final_flag=ecobj.no_data_available_code; } } catch (exception e) { system.out.println("test4 search"); final_flag=ecobj.server_response_error; } } } else { final_flag=ecobj.internet_connectivity_error; } return final_flag; } @override protected void oncancelled() { super.oncancelled(); activity_finisher(); } @override protected void onpostexecute(integer rs) { super.onpostexecute(rs); if(rs==ecobj.success_code) { set_up_search_result_display_table(); dialog.dismiss(); } else { dialog.dismiss(); if(rs==ecobj.no_data_available_code) { //set_up_search_result_display_table(); alerter(getresources().getstring(r.string.alert_title),getresources().getstring(r.string.no_receipts_date)); }* } //alert box public void alerter(string title,string msg) { alertdialog.builder builder = new alertdialog.builder(oldreceipts.this); builder.settitle(title); //builder.seticon(r.drawable.ic_launcher); builder.setmessage(msg); builder.setpositivebutton(oldreceipts.this.getresources().getstring(r.string.okay),new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { dialog.cancel(); //finish(); } }); alertdialog alert = builder.create(); alert.show(); }*
it happen because somewhere somehow manually close (call *.close() or that) data source object - no matter is, http or database connection. thus, put object in sort of closed state, , can not requery info data source.
that's quite typical mistake when close datasource, intend use repeatedly further.
to avoid this, call *.close() method on datasource, when not need anymore. example, activity's ondestroy() method.
the answer pretty general, did not provide enough details on code.
Comments
Post a Comment