图案和QUOT;一项活动,多视图和QUOT;:优点和缺点 [英] Pattern "One activity, multiple views": Advantages and disadvantages

查看:122
本文介绍了图案和QUOT;一项活动,多视图和QUOT;:优点和缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个模式类似于模式的主要的Servlet 的(前端控制器),用于开发Web应用程序。

这种模式的主要思想:我们有一个活动,管理多个视图,而这项活动是负责重新presenting当前内容。并非所有的观点需要的功能活动(如生命周期方法),这样的主要问题是:如果我能去无活动我为什么要使用它


我发现使用这种模式的缺点如下:

  1. 官方消息不建议<一href="http://developer.android.com/guide/practices/design/seamlessness.html#multiple-activities">Overload一个活动的屏幕 但他们没有解释为什么。

  2. 我们不能使用 TabActivity ListActivity MapActivity 。但也有一些技巧去没有他们。

  3. 如果不同的屏幕有不同的菜单这是一个问题,使,没有活动。
  4. 这是必要的,以保持历史由我们自己。但它不是那么难发展。

我已经发现使用这种模式的以下优点:

  1. 在它的速度更快,以改变当前活动的内容,而不是启动另一个活动
  2. 我们可以自由地管理的历​​史,因为我们希望
  3. 如果我们只有一个活动的情况下很简单的找到和解决问题的内存泄漏

你怎么看待这个模式?你能提供其他任何优点/缺点是什么?

解决方案
  

我们不能使用TabActivity,ListAcivity,MapActivity。但也有一些技巧去没有他们。

您必须使用 MapActivity 如果你想使用图形页面。你必须使用 preferenceActivity 如果你想使用preference XML。

  

有必要保持历史由我们自己。但它不是那么难发展。

在管理自己的历史将在什么历史需要大大依赖的困难。实现历史简单的向导将是相当容易的。然而,这是一种特别简单的场景。有历史管理code在Android的相当数量,你将不得不重写任意其他情况。

您也忘了:

#5。你会容易出现泄漏内存,因为你会忘记收拾东西,而Android也不会收拾东西(因为它假定您将使用许多小的活动,他们推荐的方式)。

#6。你的状态管理配置更改(旋转,底座,SIM卡的变化,语言环境的变化,多个显示器,字体缩放)将更加复杂,因为现在你还必须弄清楚什么多余的东西(例如,历史)必须是国家的一部分, ,你必须处理所有的人都在一次,而不是活性-AT-A-时间。

#7。拥有多个入口点为您的应用变得更具挑战性(例如,多在启动图标,应用程序窗口小部件链接到某个活动不是主要的另一个,响应等)。

  

它的速度更快,以改变当前活动的内容,而不是启动另一个活动

对于大多数现代的Andr​​oid设备,速度相差不会显著大多数用户,恕我直言。

  

如果我们只有一个活动的情况下很简单的找到和解决问题的内存泄漏

除了你还有比一项活动 - 环境。记住:你的活动,或大或小,还是破坏并重新创建的配置更改

  

你怎么看待这个模式?

科斯的企业的性质的理论说,企业扩大到做事的交易成本内部变得高于对于有其他公司做同样的事情了交易成本。

理论墨菲的活动性质说,这项活动扩展到做事的交易成本内部变得比交易成本较高的有其他的活动做同样的事情。 Android开发者会倾向于用户交易模式的活动 - 东西是紧密耦合(例如,在向导的步骤)往往会在一个活动中处理,事情有关系不大(例如,浏览与搜索与设置与帮助,对有关)往往会在不同的活动来进行处理。

This pattern is similar to the pattern Main Servlet (the Front Controller) that is used for developing web applications.

The main idea of this pattern: we have one Activity that manages multiple views and this activity is responsible for representing current content. Not all views need functional of activity (e.g. life-cycle methods) so the main question is: if I can go without activity why do I have to use it?


I have found the following disadvantages of using this pattern:

  1. Official source doesn't recommend to Overload a Single Activity Screen but they don't explain why.

  2. We cannot use TabActivity, ListActivity, MapActivity. But there are some tricks to go without them.

  3. If different screens have different menu it's a problem to make that without activities.
  4. It is necessary to keep history by ourselves. But it's not so difficult to develop.

I have found the following advantages of using this pattern:

  1. It's faster to change the content of current activity than to start another activity
  2. We are free to manage history as we want
  3. If we have only one activity-context it's simpler to find and solve problems with memory leaks

What do you think about this pattern ? Could you provide any other advantages/disadvantages ?

解决方案

We cannot use TabActivity, ListAcivity, MapActivity. But there are some tricks to go without them.

You have to use MapActivity if you want to use MapView. You have to use PreferenceActivity if you want to use preference XML.

It is necessary to keep history by ourselves. But it's not so difficult to develop.

The difficulty in managing your own history will depend greatly on what the history needs to be. Implementing history for a simple wizard will be fairly easy. However, that is a particularly simple scenario. There is a fair amount of history management code in Android that you would have to rewrite for arbitrary other cases.

You also forgot:

#5. You will be prone to leak memory, because you will forget to clean up stuff, and Android will not clean up stuff (since it assumes that you will be using many small activities, the way they recommend).

#6. Your state management for configuration changes (rotation, dock, SIM change, locale change, multiple displays, font scale) will be more complicated because now you also have to figure out what extra stuff (e.g., history) need to be part of the state, and you have deal with all of them at once rather than activity-at-a-time.

#7. Having multiple entry points for your application becomes more challenging (e.g., multiple icons in launcher, app widget linking to some activity other than the main one, responding to etc.).

It's faster to change the content of current activity than to start another activity

For most modern Android devices, the speed difference will not be significant to most users, IMHO.

If we have only one activity-context it's simpler to find and solve problems with memory leaks

Except that you still have more than "one activity-context". Remember: your activity, large or small, is still destroyed and recreated on configuration changes.

What do you think about this pattern ?

Coase's "nature of the firm" theory says that businesses expand until the transaction costs for doing things internally become higher than the transaction costs for having other firms do the same things.

Murphy's "nature of the activity" theory says that the activity expands until the transaction costs of doing things internally become higher than the transaction costs for having other activities do the same things. Android developers will tend towards a "user transaction" model for activities -- things that are tightly coupled (e.g., steps in a wizard) will tend to be handled in single activity, and things that have little relationship (e.g., browse vs. search vs. settings vs. help vs. about) will tend to be handled in distinct activities.

这篇关于图案和QUOT;一项活动,多视图和QUOT;:优点和缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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