Suppose you've got a background task running with AsyncTask. At the end of this task (in onPostExecute()), you display a Dialog informing the user of success or failure. This seems to be pretty cut and dry, but there's a catch - sometimes you'll get this error:
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4479b390 is not valid; is your activity running?
at android.view.ViewRoot.setView(ViewRoot.java:468)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.view.Window$LocalWindowManager.addView(Window.java:424)
at android.app.Dialog.show(Dialog.java:239)
at android.app.Activity.showDialog(Activity.java:2488)
...
The problem lies in the fact that the AsyncTask can continue running past when the Activity itself has been finished. If a user hits the "back" button on your Activity while the AsyncTask is running, you will end up calling showDialog() after the Activity itself is finished.
My initial fix was to try to augment onCreateDialog() to handle finished activities, but unfortunately, there's no way to cancel dialog creation once you've called showDialog(); you'll cause errors returning null from onCreateDialog(). Thus, the only solution is to play it safe before you call showDialog():
protected void onPostExecute(Object result) {
if (!isFinishing()) {
showDialog(MY_DIALOG_ID);
}
}
yeah.. I faced a similar issue.. and used ur workaround.. thnx...
ReplyDelete
DeleteIntelliMindz is the best IT Training in Chennai with placement, offering 200 and more software courses with 100%
Placement Assistance. Start learning with us intellimindz, and became an expert in sap mm training in Chennai.
contact 9655877577 for more details.
SAP MM training in Chennai
SAP SD training in chennai
SAP FICO training in chennai
SAP Ariba training in chennai
SAP ABAP training in chennai
IntelliMindz is the best IT Training in Bangalore with placement, offering 200 and more software courses with 100% Placement Assistance.
DeleteAzure Course in Bangalore
DevOps Course In Bangalore
Talend Training In Bangalore
MSBI Training In Bangalore
Ab Initio Training In Bangalore
Informatica Training In Bangalore
Informatica MDM Training In Bangalore
Informatica Data Quality Training In Bangalore
CCNA Course In Bangalore
Guidewire Training In Bangalore
Many thanks for you input, I saved many hours. :)
ReplyDeleteThank you very very much... I was struggling a lot to fix this...
ReplyDeleteI think COC Mod APK and Gbwhatsapp are the best! The information you have shared here is very helpful. I really like and appreciate your work. Thanks again for it, keep us updated in future!
DeleteThis comment has been removed by the author.
ReplyDeleteThank you very much
DeleteNhững Chuyến Đi Cuộc Đời
ReplyDeleteNgẫu Hứng Du Lịch
Kien Thuc Du Lich
Book Ve Du Lich Gia Re
Splunk online training
ReplyDeleter programming online course
react online course
Sap ariba online training
qlikview online training
etl testing online training
power bi online training
Sap ehs online training
Sap erp online training
Thank you for sharing this. It was helpful. Keep sharing such things.
ReplyDeleteAlso checkout Whatsapp Aero Apk.
전북콜걸
ReplyDelete전북콜걸
음성콜걸
사천콜걸
사천콜걸
군산콜걸
군산콜걸
김해콜걸
단양콜걸
김해콜걸