Closed KhoiHuynh closed 5 years ago
Why would you want to destroy the fragment just to reset its state. I would say have reset method and reset the states of all the contributing variables. For e.g. If you want to make a editext to reset its text then just call setText with empty string and likewise. I hope this makes sense in your scenario.
hmm, thank you. that actually sounds better. i'll give that a try
Yup, going to agree with @nikhil-thakkar on this one. Removing a fragment can be an expensive operation and is entirely unnecessary if your only goal is to reset the state. I think you'd do yourself a great service to read some write-ups on managing fragment/activity states. https://developer.android.com/guide/components/fragments This would be a good place to get you started.
That all being said, if you REALLY wanted to do it the way you were saying (which I don't recommend) you could use the replace
method. Also, you should not ever be using the fragmentManager
while also using FragNav. The documentation makes this clear.
how do i destroy/remove a root fragment? I want to do this because in one of my root fragments, a user will click a button, and i want that fragment to reset it's state.
I tried
fragmentManager.beginTransaction().remove(AddLocationFragment()).commit()
but no luck, any help would be appreciated. Thanks