How can I separate the logic / interface in Android

I want my application to be structured in 2 parts: logical code and user interface.

I tried to implement this using the controller class (here I hold the logic code) inside each action. Activity sends messages to the controller and receives a response in two ways:

  • the response is returned immediately (if the action is not complex and can be completed in a short time)
  • activity sets some listeners, and the controller starts this listener when the action is completed.

    Problems arise when the controller has many objects (each object must handle many actions and for each action I have to install and run the listener): it is difficult to synchronize the code.

    I ask if you know how best to implement this mechanism.

    Thank.

+3
source share
2 answers

Personally, I view Activity as a controller. Widgets are a view. Others may disagree, and I am far from an MVC purist.

+10
source

Android methodology is pretty MVC.

Start by getting good results, and then look at empowerment on your own.

Views are connected to the controller through the user interface thread, which is the main thread of the application. You can define callbacks, etc. In XML and handle all button clicks, etc. In this thread, just using the android xml methodology.

XML View, UI Thread the Controller Background Threads/Services/Broadcast Receivers .., .

+5

Source: https://habr.com/ru/post/1784422/


All Articles