是Android FragmentTransaction.commit()方法线程安全吗?

编程入门 行业动态 更新时间:2024-10-14 10:44:24
本文介绍了是Android FragmentTransactionmit()方法线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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 FragmentTransactionmit() on another thread?

推荐答案

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

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

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

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()方法线程安全吗?

本文发布于:2023-10-24 20:26:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524925.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   方法   Android   FragmentTransaction   commit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!