7

I’m not an Android pro though I’ve developed an app consisting of more than 50 activities which makes the app really large. After 8 weeks of developing, now there are problems which caused the app difficult to maintain and upgrade. Major ones I’m dealing with are

  1. I cannot pass object reference to activities’ constructors. In fact I found the mechanisms of startActivityForResultIntentonActivityResult really limiting and results in dirty code of many constants for actions per activity and a lot of switch case that is really hard to follow the flow of app.

  2. Another problem is that I do not know how to manage the life cycle of the whole app as each activity has its own life cycle.

I had some successful experience with LWUIT and J2ME – polish which ignore J2ME MIDlets (similar to android activity) and implement their own architecture and windowing system with just one MIDlet as entry to the app. I’ve come up with the same idea for android.

To clarify, I’m thinking of an app with just one main Activity and other activities implemented as objects which extend View object and these views can be dynamically added to main activity FrameLayout and stack on each other. Activities’ logic can be implemented in such classes and I've even found a way to implement dialogs in this way. Business and state objects can be passed to their constructor and it sounds good ignoring its side effect of writing a little more code. This way listeners can also be passed to views’ constructors which makes app UI switch and flow management easier.

But the questions are:

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

I'm also aware of

None of these clearly address the issues regarding performance or practice with reasonable evidence or documented reference

Please someone help me with this

Community
  • 1
  • 1
anonim
  • 2,494
  • 6
  • 30
  • 40
  • When project is so huge, code has to be designed properly, pull out all common functionality out. better structure the data(better data structures). These will according to me help reduce lot of code. – sat Jun 02 '12 at 11:50
  • in fact I've done that. I've followed a semi MVVM pattern although android does not support data binding. the major problems reside in UI layer and views switching and glowing togather. – anonim Jun 02 '12 at 12:02

2 Answers2

6

There are popular apps in market with only one or a few activities. They use fragments and switch them. I would prefer fragments over your approach. Although I think fragments are too complex for many purposes, for your use case it would be a good solution. Your UI behavior should be in fragments, and your activity is the controller part transferring data between your fragments. Fragments also have an own life cycle.

I don't like startActivityForResult either. If I have a set of activities - all providing data - and I don't know in which order they will be called, I prefer to use a singleton class then using intents for data transmission between activities. But you have to analyze your problem to get a good solution.

Beryllium
  • 12,808
  • 10
  • 56
  • 86
Fabian Knapp
  • 1,342
  • 13
  • 27
  • Actually I've also exploited singleton pattern as the app is single user but my problem is with Intents. I cannot serialize listeners and passed them into other activities for callback processing based on user actions and about Fragment, I absolutely go along with you however when I started the project I was unaware of fragments and now in middle of the project timeline I'm afraid of using them because I'm not completely familiar with them. I may use them in the next version of the app. Thanks – anonim Jun 02 '12 at 13:26
  • 4
    How crazy would it be to build a proper MVC framework on top of Android using a single Activity as the mediator between the controllers and the rest of the Android framework? Similar to what's going on in the web world with single-page applications. Message/Email me if you're interested in collaborating on this. :) – Marchy Dec 07 '12 at 18:49
  • Im bussy at the moment but if you start such a project you can contact me could be possible that i could spend some time in future for that. – Fabian Knapp Jan 05 '13 at 18:02
1

There is already an MVC framework built, PureMVC library.

Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
Juliana
  • 11
  • 1