Intro Screen | Android App Development | Lecture#52 | Hive Learners

avatar

๐“–๐“ป๐“ฎ๐“ฎ๐“ฝ๐“ฒ๐“ท๐“ฐ๐“ผ

Hi dear Hive Learners, I hope you all are well. In this lecture, we will add some more things to the Intro activity. We will change the design of the Intro Activity and add some colors and the most important thing we will check whether the intro is already displayed or not so that users will not see the intro again and again. We will use the sharedPreferences to store a variable and update this variable when a user go through the intro for the first time. Let's jump into it.

GitHub Link

Use this GitHub project to clone into your directory. The following lecture will update it so you will never miss the latest code. Happy Coding!

What Should I Learn

  • How to save the state of Intro Class

Assignment

  • Show intro only for the first time

Procedure

First, we need to set the colors for the pages. We will add two pages. I also add a new logo of lazy-panda to use on the second page. Also, declare and initialize the SharedPreferences. I also set the Icon Layout Params and I use the height and width of 500. You can always change these parameters.

// First Page
        page1.setBackgroundColor(R.color.red);
        page1.setIconLayoutParams(500, 500, 0, 0, 0, 0);
        page1.setDisplaySkip(true);
        page1.setTitleColor(R.color.black);
        page1.setDescriptionColor(R.color.black);

        // Second Page
        page2.setBackgroundColor(R.color.black);
        page2.setIconLayoutParams(500, 500, 0, 0, 0, 0);
        page2.setDisplaySkip(true);
        page1.setTitleColor(R.color.black);
        page1.setDescriptionColor(R.color.black);

Now we need to create a list and add these pages to the list and set it in the library method setOnboardPages. We also override the on finish button click and we will use it to save the state of into class and also redirect the user to the Sign in screen.

I add a boolean value is_intro_done in the SharedPreference when the user clicks on the finish button. Also, open the Sign in screen, show a welcome message, and finish the intro screen.

Now we need to check for the is_intro_done in the Splash activity. Declare and initialize the SharedPreference and set a check for the intro. If the intro the save boolean is false then we will open the Intro screen after the Splash screen else we will open the Login screen.

 sharedPreferences = getSharedPreferences("sharedPreferences", Context.MODE_PRIVATE);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                // After two seconds 1000ms = 1 Second
                if (!sharedPreferences.getBoolean("is_intro_done", false))
                    startActivity(new Intent(Splash_Activity.this, App_Intro.class));
                else startActivity(new Intent(Splash_Activity.this, SignIn_Activity.class));
                
                finish();

            }
        }, 2000);

Let's run the app and if it is working or not.


hl_divider.png

Thank You

hl_footer_banner.png



0
0
0.000
2 comments
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.ย 
ย 

0
0
0.000
avatar

Congratulations @faisalamin! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

You received more than 30000 upvotes.
Your next target is to reach 35000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

The Hive community is in mourning. Farewell @erikasue!
0
0
0.000