Javatpoint Logo
Javatpoint Logo

Introduction Slider Example (Launch very first time when app start)

It is a good idea to implement a welcome slider screen which introduces the major features of the app. In this slider, a brief introduction of the app can be given where the user can swipe through the sliders before launching the application (MainActivity or Home-page).

Android Introduction Slider Example

In this example, we will use SharedPreferences class that is used to keep the state whether the app is being launched the first time or not. If the app is launched for the very first time, then it displays sliders before launching the application otherwise launch MainActivity.

Create an activity_main.xml file in layout directory with following code (your UI).

activity_main.xml


Create an activity_welcome.xml file and add the following code. It is used for the layout of slider.

activity_welcome.xml


Now create the layout for the welcome sliders as welcome_slide1.xml and welcome_slide2.xml in layout directory.

welcome_slide1.xml


welcome_slide2.xml


colors.xml


strings.xml


dimens.xml


Create a PrefManager.java class and add the following code. In the class, we use SharedPreferences class that keeps the preference name and a Boolean state true if the app is launched for the first time.

PrefManager.java


In the WelcomeActivity.java class file, add the following code.

In this class, we are performing the following tasks:

  • Checking the first time launch of the application using prefManager.isFirstTimeLaunch() method, if it returns true then the file MainActivity.java will be launched.
  • Adding the slider with Skip and Next buttons.

WelcomeActivity.java


In the MainActivity.java class, add the following code. This class checks the state returned by the SharedPreferences.

MainActivity.java


AndroidMenifest.java

Output:

Android Introduction Slider Example Android Introduction Slider Example Android Introduction Slider Example Android Introduction Slider Example
Next Topic#




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials