How to go back to previous fragment from activity?

前端 未结 8 1499
太阳男子
太阳男子 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 08:51

    Override onOptionsItemSelected method in activity as follows,

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }
    

提交回复
热议问题