一个活动和所有其他片段片段

2023-09-12 02:35:49 作者:让你依偎

我想实现一个屏幕活动和所有其他sreens与片段和管理所有的碎片直通活动。

I am thinking of implementing one screen with Activity and all other sreens with Fragments and managing all the fragments thru the activity.

这是个好主意吗?我的回答是否,但我仍想知道更清楚地了解这一思想。

Is it a good idea? and my answer is NO but still I want to know more clearly about this thought.

什么是思想的优点和缺点是什么?

注意:

请不要给我的链接,片段和活动。

Please don't give me the link for fragment and activity.

编辑:

下面是一些在碎片和活动:

Here is something over Fragments and activity:

优点:

片段的用意是要与活动作为子活动中使用。 片段不是替代活动。 片段意味着可重用性(要知道以什么方式可重用性可以实现的。)。 片段写code同时支持平板电脑和手机的最佳方式。

缺点:

我们需要实现的接口从片段获取数据。 对于对话,我们必须走很长的方式展现出来。

为什么要使用的片段,如果我们不考虑平板电脑? 是什么活动与片段之间的开始时间差?

Why should we use fragments if we are not considering tablets? What is the starting time difference between activity and fragment?

推荐答案

这取决于你正在创建的应用程序。我已经创建了使用这两种方法几个应用程序,并不能说一种方法总是比其他更好。最新的应用程序,我创造我用了一个活动办法和一个Facebook式的导航。当从导航列表中选择的项目我更新单个片段的容器,以显示该部分。

It depends on the app you are creating. I've created several apps using both approaches and can't say one way is always better than the other. The latest app I created I used the single Activity approach and a Facebook style navigation. When selecting items from the navigation list I update a single Fragment container to display that section.

这是说,有一个活动也介绍了很多复杂性。比方说,你有一个编辑的形式,对于一些用户需要选择或创建的项目,要求他们去一个新的屏幕。通过活动,我们只需要调用新的屏幕 startActivityForResult 片段有没有这样的事情,所以你最终存储上的活动的价值并具有主编辑片段检查活动来看看数据是否已经被选中,并应被显示给用户。

That said, having a single Activity also introduces a lot of complexities. Let's say you have an edit form, and for some of the items the user needs to select, or create, requires them to go to a new screen. With activities we'd just call the new screen with startActivityForResult but with Fragments there is no such thing so you end up storing the value on the Activity and having the main edit fragment check the Activity to see if data has been selected and should be displayed to the user.

什么亚拉文说,有关被卡住单个活动类型也是真实的,但没有真正的限制。您的活动将是一个FragmentActivity只要你并不需要一个图形页面那么有没有真正的限制。如果你想,虽然显示的地图,这是可以做到的,但你需要任何修改的Andr​​oid兼容性库有 FragmentActivity 延长 MapActivity 或使用公开发布的android-support-v4-googlemaps.

What Aravind says about being stuck to a single Activity type is also true but not really that limiting. Your activity would be a FragmentActivity and as long as you don't need a MapView then there are no real limitations. If you do want to display maps though, it can be done, but you'll need to either modify the Android Compatibility Library to have FragmentActivity extend MapActivity or use the the publicly available android-support-v4-googlemaps.

最后最让我知道开发者是走到了一个活动路线已经回到多项活动,以简化他们的code。 UI明智的,在平板电脑上,你有时使用单一活动卡只是为了实现什么都疯狂互动的设计师想出了:)

Ultimately most the devs I know that went the one Activity route have gone back to multiple Activities to simplify their code. UI wise, on a tablet, you are some times stuck using a single Activity just to achieve what ever crazy interaction your designers come up with :)

- 编辑 -

谷歌终于发布了 MapFragment 的兼容性库让您不再需要使用Android的支持-V4-的GoogleMaps黑客。阅读这里的更新:谷歌地图Android的API V2

Google has finally released MapFragment to the compatibility library so you no longer have to use the android-support-v4-googlemaps hack. Read about the update here: Google Maps Android API v2