Android: Go back to previous activity

前端 未结 23 1542
抹茶落季
抹茶落季 2020-11-22 06:52

I want to do something simple on android app. How is it possible to go back to a previous activity.

What code do I need to go back to previous activity

相关标签:
23条回答
  • 2020-11-22 07:27

    Just call these method to finish current activity or to go back by onBackPressed

    finish();
    

    OR

    onBackPressed();
    
    0 讨论(0)
  • 2020-11-22 07:27

    First, thing you need to keep in mind that, if you want to go back to a previous activity. Then don't call finish() method when goes to another activity using Intent.

    After that you have two way to back from current activity to previous activity:

    Simply call: finish() under button click listener, Or Override the following method to back using system back button:

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }
    
    0 讨论(0)
  • 2020-11-22 07:29

    Got the same problem and

    finish();  OR super.onBackPressed();
    

    worked fine for me, both worked same, but no luck with return

    0 讨论(0)
  • 2020-11-22 07:30

    Try this is act as you have to press the back button

    finish();
    super.onBackPressed();
    
    0 讨论(0)
  • 2020-11-22 07:30

    I suggest the NavUtils.navigateUpFromSameTask(), it's easy and very simple, you can learn it from the google developer.Wish I could help you!

    0 讨论(0)
  • 2020-11-22 07:32

    Try Activity#finish(). This is more or less what the back button does by default.

    0 讨论(0)
提交回复
热议问题