android - 在什么情况下我不应该使用 FragmentManager 的 executePendingTransactions()(在主线程中)?

标签 android android-fragments

我正在学习如何使用 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/

相关文章:

java - 在动画期间更改按钮功能

java - 如何从 xml 布局创建自定义 View ?

Android:具有操作栏的众多 fragment 之一,而其他 fragment 则没有

Android在主题中全局设置编辑文本样式不起作用

java - 不同选项卡的不同操作栏项目,Actionbarsherlock

java - 如何理解 fragment ?

android - 在不更改代码的情况下显示在 android studio 中创建的 bitbucket 上的新分支

java - Selendroid 滚动和轻弹不起作用

java - Eclipse 无法将我的类(class)识别为 fragment

android - 为 RecyclerView 中的其他项目重复图片