MVC Doubt on Android

2

I would 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? And does it lose a lot of performance or do it weigh heavily create so many classes? The model I know I can use in other controller and Activity.

I'm also having to always pass my controller to DAO, since I need to wait for a callback in a thread and then after the end I ask DAO to call a method of this controll that was passed by parameter. For example,% with% where in this method it would check the exception and possibly ask to display something using some method of the view (which was also passed as parameter in the controller). Is this right? I've been reading quite a bit about MVC - MVP on Android but I get confused when I'm using a Database.

    
asked by anonymous 24.08.2017 / 16:31

2 answers

1

Yes, you can use the same controller or dao for as many activities as needed without "weighing" (depending on how it is done) as on any other platform.

As for callback in your activity you can implement an interface of your controller. Something like:

public class MyController {

    public MyController(OnControllerListener onControllerListener){
        this.onControllerListener = onControllerListener;
    }

    public interface OnControllerListener {
        void onControllerCallback(String someString);
    }

    private OnControllerListener onControllerListener;

}

When the event that fires the callback onControllerListener.onControllerCallback(String someString); //Ou qualquer outra coisa que queira na activity

occurs,

And in the activity when instantiating the controller:

MyController myController = new MyController(new MyController.OnControllerListener() {
    @Override
    public void onControllerCallback(String someString) {

    }
});
    
24.08.2017 / 18:33
1

Regarding DAO, it refers to the model, it has "nothing to do" with your Activity, if you need to access 3 models, that there are 3 different DAOs, you will do this independently.

    
24.08.2017 / 16:35