Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The game I'm working on is based on different levels. I can use different activities or only one activity with different layouts ( or maybe only one layout, you have to apologize me but I'm studying alone and it's pretty hard to learn alone ).

My problem is: I'm not sure what is best way to implement levels in game. If I use only one activity as container for each level, where I design each level as different layout, how can I refresh my current activity with the new content ? To make it clear, think about "Cut the rope", is every level a different activity or they load different xml's on the same ?

I'm sorry if this question is not properly written, but I can't find more specific terms to make it better.

share|improve this question
up vote 1 down vote accepted

In general your "game" is a single activity. You may have several activities in your program if you end up include external libraries like an ad-service.

I can't speak to the "best way" to implement levels, but one way is to implement your level's view and logic in a generic manner and use simple files (text, xml whatever) to describe the specifics. This may all sound vague at first, but consider what makes up a simple level in a game such as Nintendo's "Super Mario" on the NES. The level made up of a background, some foreground objects (bricks, pits, ?-blocks), and enemies (Koopas, Goombas) and the flag pole at the end. If your level's implementation knows how to apply a background, place fore ground objects in the world, places enemies, and set the end goal, then adding the new levels is easy, just add a new level input file.

In your "Cut the Rope" example, it is unlikely (I say unlikely because I didn't write that game) that a different layout is used for each level. More likely is there is a single game activity using a single layout for the game's view. Each new level reuses the same layout and replaces the content.

share|improve this answer
thanks for the answer, my question is exactly the part of "replacing contets", to do that, should I write different xml (and with different xml I ment different layout ) or is there a better way ? – Anearion Jul 21 '12 at 22:02
For simple games I think you'd only need/want a single layout. The game's contents such as the entities I described in my answer could be configurable via an xml or text file. – snowballhg Jul 24 '12 at 20:45
thanks, so I should use the inflateView() method to load a different xml based on where I'am into the game, shouldn't I ? – Anearion Jul 24 '12 at 20:52
Sorry I don't know the answer to this. I was trying to answer in general terms, but I'm not very familiar with the specific Android APIs for layouts. – snowballhg Jul 25 '12 at 22:56

In Android, anything you can do in XML layout file can be also be created via Java code. For example, instead of using the XML tags you could have your code that initializes the level create one:
LinearLayout myLL = new LinearLayout(this);


TextView text = new TextView(this);


Check the API documentation to dynamically create the objects that your game needs to display for your level.

share|improve this answer
this isn't what i needed, but thanks anyway for the tip – Anearion Jul 24 '12 at 20:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.