How to prevent calling onCreateView when back button pressed in fragment in android

后端 未结 3 1990
执念已碎
执念已碎 2021-02-12 13:21

In my application, I have tabbar functionality. In one tab i am displaying server data in lisview, and on clicking on that detail page for that list item will be open in new fra

3条回答
  •  野的像风
    2021-02-12 13:33

    I know it has been too long to give this answer but what i am guessing is you are replacing your fragment with other one. I mean to say is you are using

    ft.replace(R.id.realTabContent, fragment);
    

    to move to other fragment which is you are using in your onItemClick so simple solution is use

    ft.add(R.id.realTabContent, fragment);
    

    instead of replacing your fragment.

    Understand the difference between replace and add. This will solve your problem.

    Replace : it will replace the original fragment and re-create the view when you come back
    Add : it will just add a new fragment to stack.

    Hope this will help someone who is facing the same problem...

提交回复
热议问题