Jak utworzyć jednorazowy ekran powitalny z preferencjami systemu Android?
Chciałbym utworzyć ekran, który wyświetla się tylko raz po uruchomieniu aplikacji. Następnie wyświetli ekran główny. Sposób, w jaki to zaimplementowałem, polegał na sprawdzeniu preferencji i ustawieniu bieżącego układu na podstawie flagi. Czy są jakieś wady w implementacji w ten sposób? Czy jest lepszy sposób?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Here is the main layout
setContentView(R.layout.main);
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
// second argument is the default to use if the preference can't be found
Boolean welcomeScreenShown = mPrefs.getBoolean(welcomeScreenShownPref, false);
if (!welcomeScreenShown) {
//Here I set the one-time layout
setContentView(R.layout.popup_message);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(welcomeScreenShownPref, true);
editor.commit(); // Very important to save the preference
}
}