Android set of dialogs for setting up app
The first time a user loads my Android 开发者_高级运维app I want to go through a few stages of setting up the app.
Basically I just want a set of dialogs that goes from one step to the next, but I don't know the best way to go about it.
I implemented a similar solution to my app. I place a breadcrumb in the preferences that indicates it's the first time the app has been run. I have a "Home" activity that is shown to the user. In onCreate, I check if the user has run the app before by looking at this preference value.
@Override
protected void onCreate(Bundle savedInstanceState)
{
if(this.application.getPreferences().isFirstTimeRun())
{
startActivity(new Intent(this, WizardStepOneActivity.class));
}
else
{
startActivity(new Intent(this, MainActivity.class));
}
}
If the user has not run the app, I launch a series of activities to walk through (i.e. Wizard-like) to set the initial settings. By using onActivityResult, I can navigate through the setup steps.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode)
{
case WIZARD_STEP_1:
Intent i = new Intent(this, WizardStepTwoActivity.class);
startActivityForResult(i, WIZARD_STEP_2);
break;
case WIZARD_STEP_2:
Intent i = new Intent(this, WizardStepThreeActivity.class);
startActivityForResult(i, WIZARD_STEP_3);
break;
case WIZARD_STEP_3:
//Set the breadcrumb to indicate that the user has set their preferences
this.application.setFirstTimeRunCompleted();
//Start main activity
startActivity(new Intent(this, MainActivity.class));
break;
}
}
I'm not sure if this is the best way or not, but it seems to work so far. Obviously, error handling should be in place to make sure they have set up the preferences, so that it is fine to set the breadcrumb.
Hope this helps, Kevin
精彩评论