Resume activity in Android

后端 未结 4 1786
情歌与酒
情歌与酒 2020-12-14 03:07

I have an app with 3 activities.

I have the main activity. This calls the second activity, which then calls the third activity. I want return to the main activity wi

4条回答
  •  北海茫月
    2020-12-14 03:22

    in order to get back to previous Activity you have to finish the visible one, use this:

    finish();
    

    If the activity was started for a result, you should give a result then, like this:

    Intent intent = new Intent();
    intent.putExtra(KEY_RESPONSE, responseData);
    setResult(RESULT_OK, intent);
    finish();
    

    And you should catch the result on the caller Activity using:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    
      switch (requestCode) {
        // Test for the code you have used to start the Activity
      }
    }
    

    Hope it helps, Regards

提交回复
热议问题