机器人:单一的活动,多视图 [英] Android: Single activity, multiple views

查看:123
本文介绍了机器人:单一的活动,多视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是一个Android亲,虽然我已经开发了一个应用程序组成的50多个活动,这使得应用程序真正的大。 8个星期显影后,现在也有造成该应用难以维护和升级问题。 主要的我负责的是

I’m not an Android pro though I’ve developed an app consisting of more than 50 activities which makes the app really large. After 8 weeks of developing, now there are problems which caused the app difficult to maintain and upgrade. Major ones I’m dealing with are

  1. 我不能通过对​​象引用活动的构造。事实上,我发现 startActivityForResult 的机制 - 意图 - onActivityResult 真的限制并导致许多常量为每个活动的行为和大量开关肮脏code 情况这是真的很难遵循应用程序的流量。

  1. I cannot pass object reference to activities’ constructors. In fact I found the mechanisms of startActivityForResultIntentonActivityResult really limiting and results in dirty code of many constants for actions per activity and a lot of switch case that is really hard to follow the flow of app.

另一个问题是,我不知道如何来管理整个应用程序生命周期的每个活动都有自己的生命周期。

Another problem is that I do not know how to manage the life cycle of the whole app as each activity has its own life cycle.

我有一些成功的经验与 LWUIT 和的 J2ME - 抛光它忽略了J2ME的MIDlet(类似机器人的活动),并只用一个MIDlet的实现自己的架构和窗口系统为进入应用程序。我想出了为Android同样的想法。

I had some successful experience with LWUIT and J2ME – polish which ignore J2ME MIDlets (similar to android activity) and implement their own architecture and windowing system with just one MIDlet as entry to the app. I’ve come up with the same idea for android.

要澄清一下,我在想一个应用程序中只有一个主活动和实现为对象延伸等活动查看对象,这些意见可以动态添加到主要活动的FrameLayout 和层叠在一起。活动逻辑可以在这样的类来实现,并且我还找到了一种方法来实现这样的对话。 商业和状态对象可以传递给自己的构造函数,它听起来不错忽视写多一点code,其副作用。这样,听众还可以传递给意见的构造,这使得应用程序的UI切换和流量管理更容易。

To clarify, I’m thinking of an app with just one main Activity and other activities implemented as objects which extend View object and these views can be dynamically added to main activity FrameLayout and stack on each other. Activities’ logic can be implemented in such classes and I've even found a way to implement dialogs in this way. Business and state objects can be passed to their constructor and it sounds good ignoring its side effect of writing a little more code. This way listeners can also be passed to views’ constructors which makes app UI switch and flow management easier.

但问题是:

  • 这是一个好的做法呢?
  • 在那岂不是导致我的表现还是内存问题?

我也知道

  • <一个href="http://stackoverflow.com/questions/2072244/android-what-is-better-multiple-activities-or-switching-views-manually">Android:什么是更好 - 多重活动或切换视图手动
  • 不超载一个活动屏幕
  • <一个href="http://stackoverflow.com/questions/4757418/pattern-one-activity-multiple-views-advantages-and-disadvantages">Pattern一个活动,多个视图。优点和缺点
  • Android: What is better - multiple activities or switching views manually?
  • Don't Overload a Single Activity Screen
  • Pattern one activity, multiple views. Advantages and disadvantages

这些都不明确解决有关性能或实践合理的证据或提供的参考

None of these clearly address the issues regarding performance or practice with reasonable evidence or documented reference

请人帮我这个

推荐答案

有流行的应用程序市场,只有一个或几个活动。他们利用碎片和切换他们。我想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.

这篇关于机器人:单一的活动,多视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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