How to go back to previous fragment from activity?

前端 未结 8 1387
太阳男子
太阳男子 2021-02-07 08:26

I\'ve got an app with nav drawer, which is switching fragments. From inside one of those fragments, I am calling a new activity. When I click back in this activity (in toolbar),

8条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 09:04

    When you call an activity from other activity's fragment, then the previous activity's instance state that is the calling activity which was having fragment's instance state will be saved in stack...so all u need to do is finish the called activity and u will have the fragment from which you called your second activity.

    @Override
    public void onBackPressed() {
    finish();
    }
    

提交回复
热议问题