android - Problem with "has leaked window" on dialog -
i writing android app give user option call different alternative number based on number tried call. have broadcastreceiver gets number being called, checks if there alternatives , show dialog starts new activity can not on own. ok except activity closed before dialog appears, window leaked exception can not see how can make works, waiting result of dialog (uncomment loop in numberdialog class) results in no exception no dialog.
the sources are:
package com.frisco.hello; import java.io.ioexception; import java.util.arraylist; import java.util.list; import android.app.alertdialog; import android.content.broadcastreceiver; import android.content.context; import android.content.dialoginterface; import android.content.intent; import android.database.sqlexception; import android.net.uri; import android.util.log; import android.widget.toast; import com.frisco.hello.util.databasehelper; public class caller extends broadcastreceiver { private static final string tag = "helloworld"; @override public void onreceive(context context, intent intent) { string intentaction = intent.getaction(); string number = getresultdata(); if (intentaction.equals(intent.action_new_outgoing_call) && number != null) { log.d(tag, "recibido evento por el numero" + number); databasehelper mydbhelper = new databasehelper(context); try { mydbhelper.createdatabase(); } catch (ioexception ioe) { throw new error("unable create database"); } try { mydbhelper.opendatabase(); }catch(sqlexception sqle){ throw sqle; } string[] results = mydbhelper.getalternatenumbers(number); if (results.length > 1) { intent = new intent(intent.action_call, uri.fromparts("com.frisco.hello.number", uri.decode(number),null)); number = null; intent.setflags(intent.flag_activity_new_task); context.startactivity(intent); } } } }
number dialog:
package com.frisco.hello; import java.io.ioexception; import android.app.activity; import android.app.alertdialog; import android.content.dialoginterface; import android.content.dialoginterface.oncancellistener; import android.database.sqlexception; import android.net.uri; import android.os.bundle; import android.util.log; import android.view.window; import com.frisco.hello.util.databasehelper; public class numberdialog extends activity { private static final string tag = "helloworld"; private charsequence[] alternates; private charsequence selected = null; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); uri uri = getintent().getdata(); string target = uri.getschemespecificpart(); log.d(tag,"decodificado el numero como "+target); databasehelper mydbhelper = new databasehelper(this); try { mydbhelper.createdatabase(); } catch (ioexception ioe) { throw new error("unable create database"); } try { mydbhelper.opendatabase(); }catch(sqlexception sqle){ throw sqle; } string[] results = mydbhelper.getalternatenumbers(target); alternates = results; new alertdialog.builder( this) .settitle( "select number" ) .setitems( results, new dialogselectionclickhandler()) .setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { finish(); } }) .setoncancellistener(new oncancellistener() { public void oncancel(dialoginterface dialog) { finish(); } }) .show(); /* while (selected == null) { try { thread.sleep(500); } catch (interruptedexception e) { ; } } log.i( tag, "seleccionado " + selected ); */ } public class dialogselectionclickhandler implements dialoginterface.onclicklistener, dialoginterface.ondismisslistener { @override public void onclick(dialoginterface dialog, int which) { log.i( tag, which+"_"+alternates[which] ); selected = alternates[which]; } @override public void ondismiss(dialoginterface dialog) { log.i( tag, "dismissed" ); selected = alternates[0]; } } }
logcat
09-29 17:52:28.309: error/windowmanager(4464): activity com.frisco.hello.numberdialog has leaked window com.android.internal.policy.impl.phonewindow$decorview@43e48270 added here 09-29 17:52:28.309: error/windowmanager(4464): android.view.windowleaked: activity com.frisco.hello.numberdialog has leaked window com.android.internal.policy.impl.phonewindow$decorview@43e48270 added here 09-29 17:52:28.309: error/windowmanager(4464): @ android.view.viewroot.<init>(viewroot.java:247) 09-29 17:52:28.309: error/windowmanager(4464): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:148) 09-29 17:52:28.309: error/windowmanager(4464): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:91) 09-29 17:52:28.309: error/windowmanager(4464): @ android.view.window$localwindowmanager.addview(window.java:424) 09-29 17:52:28.309: error/windowmanager(4464): @ android.app.dialog.show(dialog.java:241) 09-29 17:52:28.309: error/windowmanager(4464): @ android.app.alertdialog$builder.show(alertdialog.java:802) 09-29 17:52:28.309: error/windowmanager(4464): @ com.frisco.hello.numberdialog.oncreate(numberdialog.java:56) 09-29 17:52:28.309: error/windowmanager(4464): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 09-29 17:52:28.309: error/windowmanager(4464): @ android.app.activitythread.performlaunchactivity(activitythread.java:2627) 09-29 17:52:28.309: error/windowmanager(4464): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2679) 09-29 17:52:28.309: error/windowmanager(4464): @ android.app.activitythread.access$2300(activitythread.java:125) 09-29 17:52:28.309: error/windowmanager(4464): @ android.app.activitythread$h.handlemessage(activitythread.java:2033) 09-29 17:52:28.309: error/windowmanager(4464): @ android.os.handler.dispatchmessage(handler.java:99) 09-29 17:52:28.309: error/windowmanager(4464): @ android.os.looper.loop(looper.java:123) 09-29 17:52:28.309: error/windowmanager(4464): @ android.app.activitythread.main(activitythread.java:4627) 09-29 17:52:28.309: error/windowmanager(4464): @ java.lang.reflect.method.invokenative(native method) 09-29 17:52:28.309: error/windowmanager(4464): @ java.lang.reflect.method.invoke(method.java:521) 09-29 17:52:28.309: error/windowmanager(4464): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 09-29 17:52:28.309: error/windowmanager(4464): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 09-29 17:52:28.309: error/windowmanager(4464): @ dalvik.system.nativestart.main(native method)
it seems can not activate other activity while in phone call process. not trying, stopping current call showing dialog , starting new 1 different number. fix simple changing on caller class: number = null;
setresultdata(null);
indeed ends calls , allow new activity show dialog.
Comments
Post a Comment