Question

I started wondering about dependencies and invocation order between the model and the UI, respectively controller–the activity classes:

When I want to restore the state of my Android application in the method onRestoreInstanceState should I:

  1. Update the state of the model, which then makes an invocation to the activity updating the UI?
  2. Update the state of the model and then update the UI based on the model state?

So which one should I prefer?

So all I am looking here really is something like a guide how to order the dependency calls, I know that Android does not really follow MVC, so what should I use as an orientation?

Was it helpful?

Solution

I think that both 1 and 2 can happen depending on what your application is like.

Your model could broadcast change events, that activities or fragmenets can then react to updating the UI so to speak.

Or you might have a really simple model, or perhaps a transient model that is passed from activity to activity. In which case your might be more likely to just update the information in that model and then command the UI to refresh, passing the model along with it.

I'm a bit out of touch so i think both are fine as long as your clear and consistent. When i start using Fragments i might read up on whats the best way to react to changes in the model, they might prefere broadcast changes over direct calls to update/refresh.

OTHER TIPS

In typical model-view-controller implementations, one would alert the view that the model has updated so that it could re-render itself based on the updated model. As wikipedia states:

A model notifies its associated views and controllers when there has been a change in its state. This notification allows the views to produce updated output, and the controllers to change the available set of commands.

So this would be most like your number 2:

Update the state of the model and then update the UI based on the model state?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top