Reputation: 2238
I'm used to HTML development. Now I'm starting to program my first Android apps. In the tutorials I have read it looks like Android development favors using a new activity for each different form.
Nothing-less I think it's quite possible to use a single activity and use the setVisibility(View.VISIBLE|View.INVISIBLE) to show / hide GUI forms elements (This is much more similar to what I'm used with HTML-AJAX).
Is there something wrong with this way of development in Android?
Using a single activity(process) also allow to use singletons to share state and data between GUI components, while the multi-activity requires a "slightly" complex communication system using extra data to communicate the selected id, ...
I wonder what are the disadvantages of the single Activity "pattern" and why no tutorial/manual on the Internet use this technique to develop Android apps.
Do fragments have any advantage over showing/hiding views when I have no intention/interest to reuse the component?
Upvotes: 1
Views: 105
Reputation: 8478
Approach : Single Activity :
Approach : Single Activity, Multiple Fragment :
Upvotes: 2
Reputation: 30276
Do you want those code happen:
elementXScreenA.setVisibility(false);
elementYScreenA.setVisibility(false);
elementZScreenA.setVisibility(false);
elementXScreenB.setVisibility(true);
elementYScreenB.setVisibility(true);
elementZScreenB.setVisibility(true);
And then, maybe after that:
elementXScreenB.setVisibility(false);
elementYScreenB.setVisibility(false);
elementZScreenB.setVisibility(false);
elementXScreenC.setVisibility(true);
elementYScreenC.setVisibility(true);
elementZScreenC.setVisibility(true);
No. I don't want to do that !!!
That just base on your ways for funny. There are many many disadvantages to do that, and I don't think there are any advantages in this approach. I can list some. Any comments will add to this list:
No. Stop that. You just make element invisible when that element need this. For example, floating button when user scroll down list, error message textbox when no error need to show, ...
Upvotes: 0
Reputation: 98
I think there is nothing wrong, but depending on how complex your app will be, the source code can easily become very confusing!
Upvotes: 1