Where can I download the sample code for Android for reference (instructions), which appears when you first start the application and looks like a few pictures that you can scroll through?
1 answer
First of all, you need to create a class that will return to the main activity the value true if the application is started for the first time, and false if not for the first, respectively,
public class PrefManager { SharedPreferences pref; SharedPreferences.Editor editor; Context _context; int PRIVATE_MODE = 0; private static final String PREF_NAME = "androidhive-welcome"; private static final String IS_FIRST_TIME_LAUNCH = "IsFirstTimeLaunch"; public PrefManager(Context context) { this._context = context; pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE); editor = pref.edit(); } public void setFirstTimeLaunch(boolean isFirstTime) { editor.putBoolean(IS_FIRST_TIME_LAUNCH, isFirstTime); editor.commit(); } public boolean isFirstTimeLaunch() { return pref.getBoolean(IS_FIRST_TIME_LAUNCH, true); } Where isFirstTimeLaunch () returns true if the application is started for the first time.
Next you need to create a class such as WelcomeClass in which you implement ViewPager and the number of layouts you need to scroll, your application should run from this class, first of all in the onCreate() method of WelcomeClass you should get the value from the PrefManager class by SharedPreference ,
prefManager = new PrefManager(this); if (!prefManager.isFirstTimeLaunch()) { launchHomeScreen(); finish(); } which, if it returns false - the application is not launched for the first time, then an Intent should immediately open MainActivity , and if true - the application is launched for the first time, then the class will draw the layouts that you have implemented in it.
private void launchHomeScreen() { prefManager.setFirstTimeLaunch(false); startActivity(new Intent(WelcomeActivity.this, MainActivity.class)); finish(); } For more information you can follow this link.
- The link with detailed information is already inactive. - V. March
ViewPageras a container for scrolling through screens andTabLayoutfor circles - Flippy