tags:

views:

347

answers:

4

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.

+2  A: 

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.

jqpubliq
+1  A: 

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.

BrennaSoft
finishActivity(int) finishes *other* activities started with a specific request code.
jqpubliq
yeah i meant finish(). Edited previous answer.
BrennaSoft
A: 

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.

Kavin
A: 

If need to ends an activity when user clicks on the device button, how do I code it? Can please guide me?

Lynnooi