startActivity不会从蜂巢中一个片段工作 [英] startActivity doesn't work from a Fragment in HoneyComb
问题描述
本的onCreate()方法被调用,但新的活动永远不会出现。没有错误记录。
The onCreate() method is called but the new Activity never appears. No errors are logged.
跟进 - 有从一个片段调用startActivty()没有问题(我们在这导致它立即退出该次活动中的错误)
Follow up - There was no problem with calling startActivty() from a Fragment (we had a bug in the second Activity that caused it to exit immediately).
startActivity()的一个片段的作品完全一样startActivty()的一个片段之外。
startActivity() from a Fragment works exactly like startActivty() from outside a Fragment.
推荐答案
一个片段不应该叫 startActivity()
,恕我直言。片段应告知其活动,以展示什么,该活动应在决定该怎么做。在一些设备中,这可能是推出另一个活动。在一些器件中,这可能是通过增加一个片段。这一决定应在活动层次上进行,因为它是被决定哪些片段走什么样的活动,根据屏幕大小的活动。
A fragment should not be calling startActivity()
, IMHO. A fragment should be telling its activity to display something, and the activity should be deciding how to do that. In some devices, that might be launching another activity. In some devices, that might be by adding a fragment. That decision should be made at the activity level, as it is the activities that are deciding what fragments go in what activities, based upon screen size.
下面是一个示例应用程序其中,在点击一个项目 ListFragment
使任何一个单独的 DetailsFragment
来进行更新(对于大
/ XLARGE
屏幕),或者弹出一个新的活动(标准屏幕)。
Here is a sample application where a click on an item in a ListFragment
causes either a separate DetailsFragment
to be updated (for large
/xlarge
screens) or pops a new activity (for normal screens).
这篇关于startActivity不会从蜂巢中一个片段工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!