Android - Organization of levels in the game

I am new to Android development. For a school project, I am currently working on an application for children to help them learn how to write.
The application will contain many levels that use the same concept, only background changes. I made a level that works great, and now, to finish the job, I want to add levels using the code of the first.

So what is a good / regular way to do this?

I thought I could create as many actions as levels. In each new action, I could launch the first and give it a new background as a parameter. But with over 50 levels, it seems a little strange to me that I have so many activities.

Thanks for the help :)

+4
source share
4 answers

You can use fragments, especially 1 type of Fragment called ' LevelFragment', which will contain several arguments that you can pass to it so that each level is different, these arguments should refer to the contents of the level (background or something else). This way, you reuse the same layout and the same logic, simply modifying some of them based on the arguments you have.

Now all you have to do is swap fragments in the container, remaining in only one action. Since your question was fuzzy, I can not offer any recommendations for implementation at this stage, but rather a basic guide and a guide for consideration.

+1
source

, () , . , , , @Vucko .

!

+2

BaseActivity, . (, ) . , , .

+1

A snippet is your decision, you can simply pass the name of the underlying asset (give up intention).

+1
source

All Articles