I want to make dynamic Form(s) in my application, the number of forms will be decided at the run time(1 to n). To implement this I create a From Class which extends Activity. My application can have multiple instances of this Form class and navigate from one From to another.
What is the best way to implement and communicate between multiple instances of same Class(From Class).
How to communicate between two form (using Intent..?).
OR
T开发者_StackOverflow社区he other option is I take one Activity[As application] for all the forms and render every form on same activity?
Having multiple independent Activities for the different forms may not be the most obvious way from the end user point of view. You may want to consider a TabLayout to group them, or even a FrameLayout and a menu switcher.
Either way will simplify the information exchange. If using the FrameLayout, then everything is the same Activity, so the problem becomes trivial. If you use the TabLayout (perhaps the best choice), then you can store a public ArrayList on the TabActivity class, making again the exchange quite simple.
Other options to consider, if you want to follow the independent Activities path, are extras on the Intents (eg., one extra could be the form number, and another the data to be sent). Then, the activities may handle those extras inside an if/else block to compare the form number in the extra with a private field.
Lastly, you can store the data in an Application instance (there's always one single instance) and access it from each Activity.
Your other option is the right one to take... use a single activity and update its contents to match those of whatever you're currently focusing on. This will have much less overhead within your application as well as on system resources.
I think that the second solution sounds much more like "the right way to do it" I suggest instead of Implementing different Activitys, its a better solution to create multible Views like "Widgets" which are a representation of the current form you need.
Anyway, if you want to communicate between Activitys, I think the best Way is, to do this through Handler-Objects. These Handlers can handle Messages in which you can define, and put a lot of Data inside.
精彩评论