Communication objects between multiple fragments in ViewPager

前端 未结 7 1328
不知归路
不知归路 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:23

    Before choosing any option, keep in mind user can navigate or open any other app(s) so you lost your data.

    You can use onSaveInstanceState but it will somehow difficult to maintain (as you said you are new in android). You can go with with singleton by using

    • Database - Use when you want to store maintain multiple records but you have to create a database getter/setter or use any ORM like RushOrm etc.
    • SharefPreference(preferably) - If you want to use single values.

    In both cases you will create a singleton object and access its properties in your fragments.

提交回复
热议问题