If I need to do 10 similar activities, is it better I do:
- 10 activities and 10 layout?
- 1 activity and 10 layout?
- 1 activity and change the UI with visibility gone/visible?
I need an answer for:
- performance
- formality
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you use multiple activities, you will get the advantage of using the android activity stack mechanism. So if you want your users to be able to navigate with the back button, then it’s the best bet.
Also, if your activities are very similar, then you can implement common code in an abstract class, and make your 10 activities extend this common class, thus sharing some code.
and so on…
Edit : Added some sample code to show how to share things that you want to see in every sub-activity. For example, if you have a list in each activity, then you can define a specific adapter in the sub-activities in a
getAdapter()method, and bind your list to this adapter in theCommonBehaviorActivityas well as configure it (bind listeners, and so on…)On the other side, if you want to have a very fast switch between your activities, and you don’t need to be able to go “back” with the button, then visible/gone view is maybe better.