Android DialogFragment not showing when show() called in onCreate of Activity -
i have dialog fragment simple indeterminate progress bar in centre, use show network activity:
public class nativeloadingdialogfragment extends dialogfragment { public nativeloadingdialogfragment() { // blank } @override public dialog oncreatedialog(bundle savedinstancestate) { dialog dialog = new dialog(getactivity(), android.r.style.theme_dialog); progressbar indeterminateprogressbar = new progressbar(getactivity()); indeterminateprogressbar.setindeterminate(true); dialog.requestwindowfeature(window.feature_no_title); dialog.setcancelable(false); dialog.setcanceledontouchoutside(false); dialog.setcontentview(indeterminateprogressbar); dialog.getwindow().setbackgrounddrawable( new colordrawable(android.graphics.color.transparent)); return dialog; } public boolean isshowing() { return getdialog() != null; } }
i have used dialog fragment throughout app no issues, shows without issue in lots of places when call dialog.show(getfragmentmanager, null)
, when try call in onresume of settings activity not show!
i have activity settings, launches system settings change language of phone. once user changes language , activity resumes detect if language has changed , network call:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); ... mloading = new nativeloadingdialogfragment(); if (savedinstancestate != null) { if (savedinstancestate.containskey(extra_language)) { string language = savedinstancestate.getstring(extra_language); string currentlanguage = apputils.getdefaultlanguagecode( smartbankconstant.default_language, smartbankconstant.supported_languages); if (!language.equals(currentlanguage)) { updatelanguage(language.stringtolanguage(currentlanguage)); } } } } private void updatelanguage(language newlanguage) { .... getspicemanager().execute(new setlanguagerequest(newlanguage), new setlanguagerequestlistener(this)); mloading.show(getfragmentmanager(), null); getfragmentmanager().executependingtransactions(); }
the code runs no dialog appears! if network call fails have retry option calls updatelanguage(language newlanguage)
method again, , dialog appears time! doing wrong?
try approach. checks if dialog displayed, otherwise shows it.
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); ... mloading = new nativeloadingdialogfragment(); if (savedinstancestate != null) { ... } mloading.show(getfragmentmanager(), null); } private void updatelanguage(language newlanguage) { ... if (mloading != null && !mloading.isvisible()) { mloading.show(getfragmentmanager(), null); getfragmentmanager().executependingtransactions(); } }
Comments
Post a Comment