keep data persistent between fragments

时间:2015-10-29 15:54:35

标签: android android-fragments android-viewpager wizard

I am trying to build a wizard with the help of the ViewPager, in each step the user will input that data and at the end all data inserted should be presented to the user before final confirmation and send all data to the server.

What i would like to know are the following:

  1. how can I keep data persistent so at the final fragment everything will be presented to the user? I would like to use a method that will be the best in terms of performance and efficiency.

  2. On which event (onDestroy?, onDetach?) should the data be saved when the user press the "Next" button to move the next step in the wizard?

keep in mind that on each step more data should be kept.

I saw solution for wizards for android however my issue with them is that they are not RTL supported so with the ViewPager I can set the initial step using setCurrentitem() method.

https://github.com/romannurik/Android-WizardPager https://github.com/Nimrodda/WizarDroid

Appreciate your assistance

1 个答案:

答案 0 :(得分:1)

我认为这更符合您的架构设计决策。

例如,所有Fragments类都应该实现自定义接口vs onPause()方法。为什么,你下沉,主要的Fragment.class有一个onPause()?这是因为当您在视图寻呼机适配器中加载片段时,他只提供一个,但实际上他从fragmentArray加载了3个或更多片段并缓存它们,而当您只在第一个片段onPause()上处理第二个和第三个片段时依此类推。 ...在StackOverflow决定这个问题,如:

hoogle data

但它唯一的一个决定,我看到这个问题装饰者或状态机设计模式。