cppdev
cppdev

Reputation: 6973

Moving between android activities on button clicks

I am writing a android application where, on startup activity view, I have a button "DoIt". When user clicks "DoIt" button, I start another activity with different layout. On newly started activity, I have a button "Back" which should take me to the first activity. How to accomplish this. What code should I write on OnClick method of "Back" button. Also, I want the newly created activity to die after back button is pressed and application comes back to start-up activity.

Upvotes: 1

Views: 1590

Answers (3)

Kavin
Kavin

Reputation: 61

In my opinion, Android is really bad on such scenario. In Activity, it doesn't support multiple views. Consider the situation that users want to switch from these two views, or even several other views? I think in this case, iPhone is much much better.

Upvotes: -2

Robby Pond
Robby Pond

Reputation: 73484

In the new activity you can just call

this.finish();

to return to the previous activity. If you want a result from the child activity you have to launch it with startActivityForResult() and override onActivityResult in the parent. The hard back key should always go back to the parent activity by default.

Upvotes: 2

jqpubliq
jqpubliq

Reputation: 11904

Call finish() on your activity. Also, why are you making a button on screen for this? This is usually the job of the device's back button.

Upvotes: 2

Related Questions