How do I set the layout to the previous layout when the back button is pressed?

I have the following code to handle button presses in my app:

if (keycode == KeyEvent.KEYCODE_BACK && CURRENT_VIEW == MAIN_MENU_ACTIVE) { Window window = this.getWindow(); window.setContentView(R.layout.main); CURRENT_VIEW = MAIN_MENU_ACTIVE; return true; }

When it's run though, android just jumps straight to the return statement, instead of changing the layout. Is there anything that I am doing wrong here? This is for a game, so essentially I want the user to be able to navigate from the game creation screen back to the main menu by hitting the back button.

-------------Problems Reply------------

just use setContentView(R.layout.main);. Don't start using a Window, as i'm fairly sure you don't need to.

You shouldn't call setContentView multiple times. Why not simply use finish(), which would return the user to the previous activity?

Category:java Views:0 Time:2011-04-08

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.150 (s). 11 q(s)