dialog - App crashes on screen rotation when android.support.v7.app.AlertDialog is displayed and screen is rotated -
i have read related questions problem , tried (including using setretaininstance
) , have not managed find works. pared dialogfragment bone (see below) , still have problem. having read blog elsewhere in author states has tried on stackoverflow without success, have decided did , dismiss dialogfragment in onstop , recreate in onstart. thought ask in case there new solution problem.
debugging in android studio receive unfortunately app has stopped message, there not trapped exception , no logcat output.
here reduced code still fails:
import android.app.activity; import android.app.dialog; import android.app.dialogfragment; import android.os.bundle; import android.support.annotation.nullable; import android.support.v7.app.alertdialog; public class textviewdialogfragment extends dialogfragment { public textviewdialogfragment() { super(); } static public textviewdialogfragment newinstance(int title, @nullable string message, int identifier, int inputtype, int positivetext, int negativetext, boolean cancelable) { textviewdialogfragment fragement = new textviewdialogfragment(); return fragement; } @override public dialog oncreatedialog(bundle savedinstancestate) { // using appcompatactivity activity = (appcompatactivity) getactivity(); not help. activity activity = getactivity(); alertdialog.builder alert = new alertdialog.builder(activity); alert.setcancelable(true).settitle("title"); alertdialog dialog = alert.create(); return dialog; } }
i create , show dialog appcompatactivity
following code:
folderaddgetname = textviewdialogfragment.newinstance(r.string.add_folder, resources.getstring(r.string.addfoldermessage, selectedfolderview.gettext()), 1, inputtype.type_class_text | inputtype.type_text_flag_cap_words | inputtype.type_text_flag_cap_sentences, r.string.add, android.r.string.cancel, true); folderaddgetname.show(getfragmentmanager(), "addfolder");
first of all, should use android.support.v4.app.dialogfragment
instead of android.app.dialogfragment
if using appcompatactivity
. use folderaddgetname.show(getsupportfragmentmanager(), "addfolder");
Comments
Post a Comment