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 activ开发者_如何学运维ity.
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.
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.
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.
精彩评论