I am new on android programming, just did one app so far. After it’s completed, I start to think about the architecture of android application.
In my app, I use Activity as Controller similar and setContentView to add layout View, this one is working and when it switch to another View, commonly I will use another Activity, or ViewFlipper or multi View in the same Activity, switch them by using setContentView method.
Now I am thinking is it good to change this architecture to this one –
Activity
Controller
View – Layout XML
Controller class is independent from Activity, so it will be like this –
class Controller {
public View view;
.....
// logic to deal with view operation
public void init ()
{
}
}
Activity will be like this –
class MyActivity extends Activity {
ControllerOne c0 = null;
ControllerTwo c1 = null;
.....
protected void switchView (Controller c)
{
setContentView (c.view);
c.init (); // or something else to restore states of this controller
}
}
I don’t know if this one is fine for android app architecture, or is there any good ideas about android app architecture? Thanks.
I don’t think it’s a good idea to ignore Android’s MVC architecture. An activity class acts as a controller. But if you want to achieve something like using more than 1 controller for an activity, you should see Android’s Fragments.