android - Correct way to remove a DialogFragment: dismiss() or transaction.remove()? -


i still have problem due dialogfragment used on main activity.

i using code remove it:

fragmenttransaction transaction = getfragmentmanager().begintransaction(); fragment frag = getfragmentmanager().findfragmentbytag("lockdialog");  if(frag != null) {     transaction.remove(frag);     transaction.commit(); } 

the problem still getting crashes due fact dialog has duplicates (meaning dialog not removed sometimes).

so question is: right way remove dialogfragment or must used fragments?

do have use dismiss() method time?:

fragment lockfragment = getfragmentmanager().findfragmentbytag("lockdialog");  //if dialog exist, dismiss if(lockfragment != null  && lockfragment instanceof lockdialogfragment) {     lockdialogfragment lockdialog = (lockdialogfragment) lockfragment;     lockdialog.dismiss(); } 

this biggest bug on 1 of apps want sure before choosing 1 or other.

thanks!

edit: realized current problem maybe due fact commits can delayed, add executependingtransactions see if gets better. still brings question, necessary call transaction.remove() if dialog has been dismissed? using dismiss() more straightforward , safe using transactions?

dialogfragment.dismiss() correct way. documentation:

dismiss fragment , dialog. if fragment added stack, stack state , including entry popped. otherwise, new transaction committed remove fragment.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -