Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I separate Logic/UI in Android

Tags:

android

I want as my application to be structured in 2 parts: the logic code and the UI.

I've tried to implement that using a controller class(here I keep the logic code) inside of each activity. The activity send messages to controller and receive the answer in two ways:

  1. the answer is returned immediately (if the action is not complex and it can be done in a verry short time)
  2. the activity set some listeners and the controller fire this listener when the action is complete.

    The problems appears when the controller have a lot of objects(each object should handle a set of actions and for each action I have to set & trigger a listener): it is hard to keep the code syncronized.

    I'm asking if you know a better way to implement this mechanism.

    Thank you.

like image 515
Ungureanu Liviu Avatar asked Dec 02 '22 03:12

Ungureanu Liviu


1 Answers

Personally, I consider the Activity to be the controller. Widgets are the view. Others may disagree, and I am far from an MVC purist.

like image 179
CommonsWare Avatar answered Dec 17 '22 04:12

CommonsWare