android - Best way of handling recreated dialog fragment after activity is destroyed and recreated -
i have activity may show dialogfragments. activity needs response dialogs. use listener. in activity:
progressmarkdialog dialog = new progressmarkdialog(); dialog.setonprogressmarkselected(new progressmarkdialog.onprogressmarkselected() { @override public void onselect(final int a) { //some code.. } });
in dialog:
public void setonprogressmarkselected(onprogressmarkselected onprogressmarkselected) { this.onprogressmarkselected = onprogressmarkselected; }
this code works fine until somehow activity destroyed, dialog still open. program crash nullpointerexception because onprogressmarkselected null.
i can use
@override public void onattach(final activity activity) { super.onattach(activity); onprogressmarkselected = (onprogressmarkselected) activity; }
and implement interface in activity. if have few dialogfragments, means should implement few interface in activity , code messy. android best practice case?
in opinion best way stick standard positive/negative buttons , attaching dialoginterface.onclicklistener
shown in http://developer.android.com/reference/android/app/dialogfragment.html
look @ way: standard android user expects see positive and/or negative button in dialog. activity -if needed- should informed result (positive, negative input data) of dialog. other input validation should handled inside dialogfragment
Comments
Post a Comment