我正在学习如何使用 fragment ,到目前为止我遇到过很多小问题。 FragmentManager 的 executePendingTransactions
方法看起来可能有一些自己的方法,特别是因为在官方 Android 文档的描述中有这个注释:
If you want to immediately executing any such pending operations, you can call this function (only from the main thread) to do so. Note that all callbacks and other related behavior will be done from within this call, so be careful about where this is called from. http://developer.android.com/reference/android/app/FragmentManager.html#executePendingTransactions()
对我来说听起来像是一个非常神秘的警告。这些“回调和其他相关行为”将如何影响我的应用程序?当从主线程调用这个函数时,这会导致问题吗?我找不到任何具体的例子,所以我向任何揭开这个警告神秘面纱的人寻求帮助:什么时候我应该不使用executePendingTransactions
的一些例子主线程,如果我这样做会发生什么可怕的事情?或者只要它在主线程中,它就总是可以安全使用吗?
最佳答案
当您在 UI 线程以外的线程中时,不应调用此方法。
它在 same lines 中指定:
If you want to immediately executing any such pending operations, you can call this function (only from the main thread) to do so.
关于android - 在什么情况下我不应该使用 FragmentManager 的 executePendingTransactions()(在主线程中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16253559/