I'm just curious about whether or not I have to call this on the UI-Thread or not. According to the documentation, the commit
is run on the UI-thread further on in the future, when it has time to do so. If this is the case, can I run FragmentTransaction.commit()
on another thread?
This question is a year old but I wanted to address it because I suspect it's an issue that a lot of people will encounter.
Working with FragmentTransactions, including calling the commit method, is safe to do on non-UI threads because none of the work that occurs within the FragmentTransaction directly manipulates the UI. The method calls on the FragmentTransaction are simply packaged up as a list of instructions of work to be performed.
Once you call the commit method, that package of instructions is then sent over to the UI thread for processing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With