Android - Simulate Back Button

后端 未结 5 1791
北荒
北荒 2021-02-01 11:57

When i press a button in my app, I need to return to the last activity.

Any ideas?

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-01 12:19

    Calling finish() from the activity you want to end should take care of this.

    Edit many years later: This still works, but it's a bit of a heavy-handed approach. When I originally posted this, Fragments didn't exist, and (as several commenters have pointed out) this doesn't work quite the same way when there are Fragments involved. There are better approaches now if you're using Fragments.

提交回复
热议问题