Reputation: 103
I'm working on an app where basically i have X different activities but everyone has a layout equals to the rest. To let you understand better let me do an example: Suppose i have a game where you have to guess 10 words each level, and I have 5 levels, basically I have in every view 10 question. So is better to have 5 different activities or only one activity and 5 layouts, one for every level ? Looking around on the web i did not find a good answer, someone told that Android is based on activity, so 10 different ones is the way to go, but was only a guessing, nothing technical.
Upvotes: 1
Views: 513
Reputation: 17830
Don't make 10 Activities. Don't make 5 layouts. All questions look the same except for the text, right? Don't Repeat Yourself.
Simplify your life reuse the same Activity and Layout for every single question. When you start the activity, you can pass in data using the .putExtra() methods. Use that to pass in the things that change, like the question text, the correct answer, and the current level.
Upvotes: 2
Reputation: 10704
I would do 1 layout and then program the levels onto it.
Doing a brick breaker game, or tetris, or puzzle game wouldnt want you to have a million diff activity options, but more like 1 layout and 1 activity will populate accordingly.
Usually you can do something like [home] -> {play, options, exit}
[play] -> {new game, level select}
[options] -> ....derp...
[exit] -> ....derp...
[newgame] --> start activityA where level = 1
[level select] -> click a link which will start activityA with a level = selected.
1 activity which will spawn your information safe and nicely... far far better imo.
Upvotes: 0