Skip to content

Commit 724a686

Browse files
authored
Merge pull request #601 from czan/welcome-section-rotation
Fix first run wizard crashes on screen rotation - fixes #596
2 parents d790b80 + 932c380 commit 724a686

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

app/src/main/java/org/gnucash/android/ui/wizard/FirstRunWizardActivity.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)