@@ -83,19 +83,17 @@ public class FirstRunWizardActivity extends AppCompatActivity implements
8383
8484
8585 public void onCreate (Bundle savedInstanceState ) {
86+ // we need to construct the wizard model before we call super.onCreate, because it's used in
87+ // onGetPage (which is indirectly called through super.onCreate if savedInstanceState is not
88+ // null)
89+ mWizardModel = createWizardModel (savedInstanceState );
90+
8691 super .onCreate (savedInstanceState );
8792 setContentView (R .layout .activity_first_run_wizard );
8893 ButterKnife .bind (this );
8994
9095 setTitle (getString (R .string .title_setup_gnucash ));
9196
92- mWizardModel = new FirstRunWizardModel (this );
93- if (savedInstanceState != null ) {
94- mWizardModel .load (savedInstanceState .getBundle ("model" ));
95- }
96-
97- mWizardModel .registerListener (this );
98-
9997 mPagerAdapter = new MyPagerAdapter (getSupportFragmentManager ());
10098 mPager .setAdapter (mPagerAdapter );
10199 mStepPagerStrip
@@ -197,6 +195,24 @@ public void onClick(View view) {
197195 updateBottomBar ();
198196 }
199197
198+ /**
199+ * Create the wizard model for the activity, taking into accoun the savedInstanceState if it
200+ * exists (and if it contains a "model" key that we can use).
201+ * @param savedInstanceState the instance state available in {{@link #onCreate(Bundle)}}
202+ * @return an appropriate wizard model for this activity
203+ */
204+ private AbstractWizardModel createWizardModel (Bundle savedInstanceState ) {
205+ AbstractWizardModel model = new FirstRunWizardModel (this );
206+ if (savedInstanceState != null ) {
207+ Bundle wizardModel = savedInstanceState .getBundle ("model" );
208+ if (wizardModel != null ) {
209+ model .load (wizardModel );
210+ }
211+ }
212+ model .registerListener (this );
213+ return model ;
214+ }
215+
200216 /**
201217 * Create accounts depending on the user preference (import or default set) and finish this activity
202218 * <p>This method also removes the first run flag from the application</p>
0 commit comments