Я не уверен, на каком языке вы пишете код. Но позвольте мне объяснить в Java, в котором я опытный. Вы можете легко адаптировать это к любому другому языку.
Сначала создайте класс PreferencesManager следующим образом:
public class PreferencesManager {
SharedPreferences pref;
SharedPreferences.Editor editor;
Context _context;
// shared pref mode
int PRIVATE_MODE = 0;
// Shared preferences file name
private static final String PREF_NAME = "splash-welcome";
// Shared preference variable name
private static final String IS_FIRST_TIME_LAUNCH = "IsFirstTimeLaunch";
// Constructor
public PrefManager(Context context) {
this._context = context;
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = pref.edit();
}
// This method to be used as soon as the fist time launch is completed to update the
// shared preference
public void setFirstTimeLaunch(boolean isFirstTime) {
editor.putBoolean(IS_FIRST_TIME_LAUNCH, isFirstTime);
editor.commit();
}
// This method will return true of the app is launched for the first time. false if
// launched already
public boolean isFirstTimeLaunch() {
return pref.getBoolean(IS_FIRST_TIME_LAUNCH, true);
}
}
Теперь в каждом упражнении вы должны проверить, запускается ли приложение впервые:
PreferencesManager preferencesManager = new PreferencesManager (this);
if (!preferencesManager.isFirstTimeLaunch()) {
// Set shared preference value to false so that this block will not be called
// again until your user clear data or uninstall the app
preferencesManager.setFirstTimeLaunch(false);
// Write your logic here
}
Возможно, это не точный ответ, который вы ищете. Но это может указать вам правильное направление:)