I’d like to create a screen that only shows once after the application starts. Afterward, then it will only show the main screen. The way I implemented this was just to check the preferences and set the current layout based on a flag. Are there any draw backs to implementing it this way? Is there a better way?
@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
}
}
Try with Application version code. Below is an example code that I have used;