Android: single activity, multiple views

I am not an Android developer, although Ive developed an application consisting of more than 50 actions, which makes the application really big. After 8 weeks of development, now there are problems that make the application difficult to maintain and update. The main ones I'm dealing with are

  • I cannot pass an object reference for action constructors. In fact, I found that the mechanisms startActivityForResult - Intent - onActivityResult really restrict and lead to a dirty code of many constants for actions for activity and a lot of switch case , which are really difficult to track the flow of the application.

  • Another problem is that I do not know how to manage the life cycle of the entire application, since each type of activity has its own life cycle.

I have had successful experience with LWUIT and J2ME - polish , which ignore J2ME MIDlets (similar to android activity) and implement their own architecture and window system with one midlet as an input to the application. Ive come up with the same idea for Android.

To clarify, Im is thinking of an application with only one main Activity and other actions implemented as objects that extend the View object, and these views can be dynamically added to the main FrameLayout activity and stacked on top of each other. The logic of actions can be implemented in such classes, and I even found a way to implement dialogs in this way. Business and state objects can be passed on to their constructor, and that sounds good, ignoring its side effect of writing a bit more code. In this way, listeners can also be passed on to view designers, which simplify customization of the user interface and flow control.

But there are questions:

  • Is this a good practice?
  • Wouldn't that lead me to performance or memory issues?

I also know

None of these issues explicitly address issues related to effectiveness or practice, with substantiated evidence or a documented link.

Please help me with this.

+7
source share
2 answers

There are popular applications on the market with one or more actions. They use fragments and switch them. I would prefer snippets over your approach. Although I find fragments too complex for many purposes, for your use case this would be a good solution. Your user interface behavior should be in the form of fragments, and your activity is part of the controller that transfers data between your fragments. Fragments also have their own life cycle.

I also don't like startActivityForResult . If I have a set of actions - all providing data - and I don’t know in what order they will be called, I prefer to use a singleton class and then use intentions to transfer data between actions. But you must analyze your problem to get a good solution.

+6
source

The MVC framework, the PureMVC library , has already been created.

+1
source

All Articles