Pankaj Khurana
Pankaj Khurana

Reputation: 3271

How do i revert to the first screen?

In my application grid view is loaded first. Selecting an image renders a linear layout view(second screen) . In the second screen some action is performed on click of a button. Now what i am curious to know how can i revert to the first screen from the second screen on click of that button?

I have tried MoodJournal.this.finish(); but it goes to the home screen.

I have also tried MoodJournal.this.setContentView(R.layout.main); but it renders a blank screen.

Please help me on this

Thanks

Pankaj

Upvotes: 0

Views: 100

Answers (2)

Alexandru Cristescu
Alexandru Cristescu

Reputation: 3948

Pankaj, if I understand correctly, you're not making a different Activity for each screen, which is the recommended way of doing things. That is to say, for the second screen it is not sufficient to "create a linear layout at runtime", you must write a new class that extends Activity and invoke it from the first screen by using the Intent mechanism, and apply that linear layout on it's onCreate(). If you do that, the screen stack is automatically managed for you.

There are plenty of tutorials on how to do this, but the basic idea you want to take with you is that IN GENERAL (there can be exceptions) one screen = one class that extends Activity.

Upvotes: 1

LordTwaroog
LordTwaroog

Reputation: 1738

Didn't you call finish() in previous activities?

Upvotes: 0

Related Questions