How to go back to previous fragment from activity?

前端 未结 8 1399
太阳男子
太阳男子 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:44

    Sorry, I don't have enough reputation to leave a comment. So I have to guess. I once had the same issue. Sounds like a problem related to the activity lifecycle (http://developer.android.com/reference/android/app/Activity.html#ProcessLifecycle). Be sure to add your first fragment only once, because your activity's fragment manager is capable of the lifecycle. Thus, the statement that adds the first fragment to your fragment manager should be surrounded by if (savedInstanceState == null) { ... }.

提交回复
热议问题