Android应用程序架构 - 建议的模型是什么?

问题描述:

以同样的方式,网页或桌面应用可能有三层或三层 - 例如,UI,业务,数据 - Android应用程序的建议结构是什么?你如何组合课堂,你有什么层次?

In the same way a web or desktop app might have three or n tiers - UI, Business, Data for example - what is the suggested structure for an Android application? How do you group classes together, what layers do you have etc?

我刚刚启动Android开发人员(基于互联网的应用程序,必须响应传入的通知),并且对我所针对的结构没有真正的感觉。

I'm just starting Android dev (an internet-based app that must respond to incoming notifications) and have no real feel for the structure I'm aiming at. Suggestions appreciated.

Android中的动作,观点和活动是以Android UI的方式烘焙而成,实现模型视图模型,其结构上类似于(与同一系列)模型视图控制器。

The actions, views and activies in Android are the baked in way of working with the Android UI and are an implementation of a model-view-viewmodel pattern, which is structurally similar (in the same family as) model view controller.

为了最好的了解,没有打破这种模式的方式。它可能会完成,但是您可能会失去现有模型的所有好处,并且必须重写自己的UI层才能使其工作。

To the best of my knoweledge, there is no way to break out of this model. It can probably be done, but you would likely lose all the benefit that the existing model has, and have to rewrite your own UI layer to make it work.

你可以在下面找到MVC:

  • You define your user interface in various XML files by resolution/hardware etc.
  • You define your resources in various XML files by locale etc.
  • You store data in SQLite or your custom data in /assets/ folder, read more about resources and assets
  • You extend clases like ListActivity, TabActivity and make use of the XML file by inflaters
  • You can create as many classes as you wish for your model, and have your own packages, that will act as a structure
  • A lot of Utils have been already written for you. DatabaseUtils, Html,

没有可以遵循的单个MVC模式。 MVC只是表示你不应该混合数据和查看,视图负责持有正在处理数据的数据或类直接影响视图。

There is no single MVC Pattern you could obey to. MVC just states more or less that you should not mingle data and view, so that e.g. views are responsible for holding data or classes which are processing data are directly affecting the view.

但是,尽管如此,Android处理类和资源的方式有时甚至是被迫遵循MVC模式。在我的反对中更复杂的是有时候对这种观点负责的活动,但是同时作为一个控制者。

But nevertheless, the way Android deals with classes and resources, you're sometimes even forced to follow the MVC pattern. More complicated in my oppinion are the activites which are responsible sometimes for the view but nevertheless act as an controller in the same time.

如果你定义你的观点和布局在xml文件,从res文件夹加载您的资源,如果您避免或多或少地在代码中混合这些东西,那么您可以遵循MVC模式。

If you define your views and layouts in the xml files, load your resources from the res folder, and if you avoid more or less to mingle this things in your code, then your anyway following a MVC pattern.