Communication objects between multiple fragments in ViewPager

前端 未结 7 1509
不知归路
不知归路 2021-02-07 06:53

I have 5 fragments in ViewPager used to fill business object with several fields step by step, in each step some of those fields will be set. I\'ve read many articl

7条回答
  •  佛祖请我去吃肉
    2021-02-07 07:16

    1. you can save your data in onSaveInstanceState() event of the activity in case your process will go into the background. you can restore your data in onCreate() event by using Bundle and getExtras().

    2. you can save your data in application class and the data will still be there in case your process will go into the background.

    i prefer the first option because you don't want to make a mess in the application class with all the data from different activities and fragments. I hope i could help :)

提交回复
热议问题