是Android FragmentTransaction.commit()方法线程安全吗? [英] Is Android's FragmentTransaction.commit() Method Thread Safe?

查看:291
本文介绍了是Android FragmentTransaction.commit()方法线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是好奇,我是否没有把这种在UI线程与否。根据该文件,在提交是UI线程上进一步在未来运行,当它有时间这样做。如果是这样的话,我可以在另一个线程上运行 FragmentTransaction.commit()

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?

推荐答案

不完全明白你的意思。你可能总是有它发送一个消息给UI线程调用FragmentTransaction.commit()。任何其他线程

Not exactly sure what you mean. You may always have any other thread which sends a message to the UI thread invoking FragmentTransaction.commit().

不过,我不明白为什么你不请立即提交的所有事务之后。

However, I do not quite understand why you do not call commit immediately after all the transactions.

我甚至会想到,你甚至可以体验空指针错误应该有过任何改变的片段或者其取决于数据 - 这会导致您的应用程序的不同的状态时相比,你会打电话立即提交 - 我的意思是在延迟期间。

I would even expect that you may even experience NullPointer Errors should there have been any changed to the fragments or their depending data - during the delay I mean - which cause a different state of your app than when you would call commit immediately.

此外,在这种情况下,你应该叫 fragmentManager.executePendingTransactions(),以确保所有的更改将作出,否则你可能会认为交易已经发生 - 这其实他们还没有。

Also in that context you should call fragmentManager.executePendingTransactions() to ensure that all your changes will be made, otherwise you may assume that the transactions have taken place - which in fact they haven't yet.

这篇关于是Android FragmentTransaction.commit()方法线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆