Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the role of the Activity class in MVC?

I know there have been quite a few questions about this, however, I'm still struggling to understand what role the Activity class should play when implementing the traditional Model-View-Controller design pattern on Android?

My gut feel is that it should be the Controller, however that means a one-to-one relationship between UI screens (since you must have one Activity per screen) and controllers, which defeats the point of MVC's loose coupling between the different components.

like image 284
donturner Avatar asked Feb 15 '12 10:02

donturner


People also ask

What is the role of activity in Android?

An activity provides the window in which the app draws its UI. This window typically fills the screen, but may be smaller than the screen and float on top of other windows. Generally, one activity implements one screen in an app.

What is the role of a controller class in MVC pattern?

A controller is responsible for controlling the way that a user interacts with an MVC application. A controller contains the flow control logic for an ASP.NET MVC application. A controller determines what response to send back to a user when a user makes a browser request.

What's the role of the model in MVC?

Model Responsibilities The Model in an MVC application represents the state of the application and any business logic or operations that should be performed by it. Business logic should be encapsulated in the model, along with any implementation logic for persisting the state of the application.

What is the use of activity?

An Android activity is one screen of the Android app's user interface. In that way an Android activity is very similar to windows in a desktop application.


1 Answers

You are right. The xml interfaces could be defined as the View and your other class working with data as the Model.

The activity receive all the events and user inputs from the View ,so, we can easily said that it is the Controller.

But let's be clear , it's not a perfect (does it really exist ?) MVC

Have a look to this question , and more specifically , the first comment of the accepted answer, it may be useful

like image 93
grunk Avatar answered Oct 16 '22 18:10

grunk