android - DialogFragment lifecycle behavior -


i have custom dialogfragment overrides ondismiss() method:

@override public void ondismiss(dialoginterface dialog) {     ((myactivity) getactivity()).ondismiss();     super.ondismiss(dialog); }  

the problem method executed after ondetach(), in turn trigger nullpointerexception. there way safely detect dialog dismissal before it's detached?

i dismissed dialog hosted in dialogfragment by: (1) calling dialog.dismiss(), (2) touching outside dialog, , (3) pressing back. in each case, when ondismiss() called, getactivity() not null (i.e. fragment attached). time when ondismiss() called when fragment not attached during restart caused configuration change. in case, ondismiss() called old fragment being destroyed. situation, not need notify activity dialog dismissed, because dialog recreated result of restart processing. in opinion, code posted, added check, acceptable , safe way handle dialog dismiss events:

@override public void ondismiss(dialoginterface dialog) {     if (getactivity() != null) {         ((myactivity) getactivity()).ondismiss();     }     super.ondismiss(dialog); } 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -