Yeah, you should consider a simple state machine design.
Say you created an Enum
, ERuntimeState
, which has two components;
enum ERuntimeState { INITIALIZE, BEEN_INITIALIZED; }
You can view a useful example of saving data using SharedPreferences
here, if you need a reminder. When using SharedPreferences
, you're able to query an existing storage flag for your application, and if a variable hasn't been set before, you can set it's default value. So, when the application first runs, you can use SharedPreferences
to check for a saved instance of ERuntimeState
, using INITIALIZE
as the default that will be picked if there's no existing save data.
Once this is done, you can use the ERuntimeState
you've fetched to configure what contents you want to load on your screen; this is where you can display your first-time launch interface. We have to make sure that once this state is entered, you use shared preferences to save an ERuntimeState
value of BEEN_INITIALIZED
, so you don't execute the initialization step again on your next run.
Of course, by defining this enum
, we're not limited to just two states. Otherwise we'd just use a boolean, and that's inflexible.
As an aside, this might be quite hard to debug! You might want to make sure you don't save the flag in your initialization state whilst you're debugging, otherwise you'll have to keep clearing all of the application's cached data in order to emulate an initial launch.