2
Would you like to know the following, in Android development using MVC, for each Activity I have to have a Controller and maybe a DAO? Or can I use the same Controller class that controls two Activity? Does it lose a lot of performance or does it weigh a lot to create so many classes? The model I know I can use in other controller and Activity.
I’m also always having to pass my controller to the DAO, because I need to wait for a callback on a thread and then after the finish I ask the DAO to call a method of this Controll that was passed by parameter. For example controller.retornoCadastroUsuario(exception)
where in this method he would check the Exception and possibly ask to display something using some view method (which was also passed as parameter in the controller). That’s right? I’ve been reading a lot of MVC - MVP on Android but I get confused when I’m using a database.
What about the Controll question? It is necessary to have one for each Activity?
– Hamon
@Hamon, brother, I only answered about the DAO because it is a Pattern that can be used in various projects, and I use it directly in my web projects, not only in mobile projects. I know a little Android, but I don’t know
Controll
– Henrique Santiago
I think the controlls would be for each entity. because the methods can be called wherever needed. For example, in Usuario_controller, you have the login() method that you can call in Activity login, not in Activity of registration
– adventistaam
If you are a Controller, responsible for passing information from template to view, to Activity, I agree to be one for each model as well.
– Henrique Santiago
@Adventistaam the entity you would be a Model? But I would have to create in this example two constructs in the controller where one receives Loginactivity and another Loginactivity to trigger visualization methods (which are in Activity) inside the controller. Would it be a problem? That’s why you doubt creating a controller for Activity.
– Hamon
Yes. The Model. Usually I use the controller without constructor
– adventistaam
If you do not use constructor then you pass Activity as parameter in the controller method?
– Hamon
Actually I use the controller to communicate with DAO. Type I only send the same values. What would be your idea to pass the Activity?
– adventistaam
Pass the Activity to the Controller to call some show methodMensage or irParaNovaActivity (which is in Activity) which are things that will involve the display layer "cannot" be executed directly by the Controller. For example, controller does the checks and now needs to open a dialog, so this method to open the dialog would be in the view.
– Hamon