且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

机器人:单一的活动,多视图

更新时间:2023-11-19 07:56:22

有流行的应用程序市场,只有一个或几个活动。他们利用碎片和切换他们。我想preFER片段在你的方法。虽然我觉得片段用于多种目的过于复杂,为您的使用情况下,这将是一个很好的解决方案。您的用户界面行为应该是在片段,以及你的活动是控制器部分的片段之间的数据传输。片段也有自己的生命周期。

There are popular apps in market with only one or a few activities. They use fragments and switch them. I would prefer fragments over your approach. Although I think fragments are too complex for many purposes, for your use case it would be a good solution. Your UI behavior should be in fragments, and your activity is the controller part transferring data between your fragments. Fragments also have an own life cycle.

我不喜欢 startActivityForResult 无论是。如果我有一系列的活动 - 所有提供数据 - 我不知道以何种顺序,他们将被调用,我preFER使用一个单独的类,然后使用意图的活动之间的数据传输。但是你要分析你的问题得到了很好的解决。

I don't like startActivityForResult either. If I have a set of activities - all providing data - and I don't know in which order they will be called, I prefer to use a singleton class then using intents for data transmission between activities. But you have to analyze your problem to get a good solution.