Android app architecture - what is the proposed model?

In the same way, a web application or a desktop application can have three or n levels - user interface, business, data, for example, what is the proposed structure of the Android application? How do you group classes together, what are your layers, etc.?

I am just starting Android dev (an internet application that should respond to incoming notifications) and have no real sense of the structure I'm aiming at. Suggestions appreciated.

+55
android design design-patterns architecture
Jul 23 '10 at 17:00
source share
5 answers

Actions, views and actions in Android are baking in working with the Android UI and implementing the model-view-viewmodel template, which is structurally similar (in the same family as) the model view controller.

At best, there is no way out of my know-how to break out of this model. It may be possible, but you are likely to lose all the benefits that the existing model has, and you must rewrite your own user interface layer to make it work.

You can find MVC in the following files:

  • You define your user interface in various XML files by resolution / hardware, etc.
  • You define your resources in various XML files by language, etc.
  • You save data in SQLite or your user data in / assets / folder, read more about resources and assets
  • You distribute clans like ListActivity , TabActivity and use the XML file inflaters
  • You can create as many classes as you want for your model, and have your own packages that will act as a structure.
  • Many Utils are already written for you. DatabaseUtils, Html,

There is no single MVC template that you could obey. MVC simply states more or less that you should not mix data and view, for example, views are responsible for storing data or classes that process data directly affect the view.

Nevertheless, the Android method deals with classes and resources, sometimes you are even forced to follow the MVC pattern. More complicated in my work are actions that are sometimes responsible for the presentation, but nevertheless act as a controller at the same time.

If you define your views and layouts in xml files, load your resources from the res folder, and if you avoid more or less mixing this in your code, then you still follow the MVC pattern.

+16
Jul 23 '10 at 17:35
source share

IMHO, Android β€œwants” to follow the MVC pattern, but view and controller are usually related to each other in actions.

This makes the unit test more difficult and difficult for him to comply with the principle of single responsibility .

I found a really beautiful Android architecture presented here , an idea may come up. Everything is weakly interconnected, it is easier to test and edit.

Obviously, there are many other possibilities (for example, the MVP pattern ( Model View Presenter ) - and here are the answers talking about MVP in Android ), but you should take a look at it anyway.

+16
Apr 03 2018-12-12T00:
source share

I understand that this question is very old, but I think it may be useful for others, such as myself, who stumbled upon it through a search.

I've been working on Android for 9 months on the server side, where fully unit testing and tiered architectures are common and work well.

Through a lot of trial and error, and I highly recommend using the Model View Presenter template rather than the Model View Controller.

The huge problem that I discovered is that Activities / Fragments has a life cycle that is out of your control and can lead to unexpected problems.

For example, our main Android application requires use in landscape mode on tablets. We do this in OnCreateView() or OnCreate() .

In the Nexus 7 view, the portrait is displayed by default, so what happens is that it starts its activity in portrait mode, and our code says that the transition to the landscape, and the android ultimately creates the activity class 3 times!

We connected network requests to onCreate , and in this case they end 3 times.

Of course, we can add logic to search for repeated calls, but, in my opinion, it would be better to try architecturally to separate the user interface from business logic.

My recommendation would be to use the factory pattern to create presenters from this operation, but make sure that the factory returns only one instance. The host can then contain the logic to perform a network request, find duplicates, and return caching results and overall business logic.

When the results from network calls are returned, either a message to the bus, such as Otto, that registered the activity (register for the event on onResume() and unregister during onPause() ), or make sure that the callback interface implemented activity has been updated until the last activity in the presenter.

Thus, the code in presenter down is a test module and does not depend on checking a broken user interface level.

+16
Dec 20 '14 at 18:02
source share

MVP is the last architecture that most people follow, here's a little documentation. How Uncle Bob's Clean Architecture says: "Architecture is an intention, not a framework."

Watch this video , it’s just reasonable.

+6
Aug 21 '15 at 15:05
source share

Here is a dedicated project for an Android architecture diagram with well-documented source codes. All are based on the MVP pattern with several twists. Also check the comparison of different solutions based on lines of code, testability, training costs, their support to increase data complexity. It depends on the specially developed application and context (time to market, developers, plans for the future, etc.), which is best suited.

+1
Jan 16 '17 at 15:30
source share



All Articles