Start a fragment via Intent within a Fragment

前端 未结 4 1431
旧巷少年郎
旧巷少年郎 2020-11-29 03:10

I want to launch a new fragment to view some data. Currently, I have a main activity that has a bunch of actionbar tabs, each of which is a fragment. So, within a tab fragme

4条回答
  •  日久生厌
    2020-11-29 03:32

    You cannot open new fragments. Fragments need to be always hosted by an activity. If the fragment is in the same activity (eg tabs) then the back key navigation is going to be tricky I am assuming that you want to open a new screen with that fragment.

    So you would simply create a new activity and put the new fragment in there. That activity would then react to the intent either explicitly via the activity class or implicitly via intent filters.

提交回复
热议问题