Android App Development | Lecture#29 | Hive Learners

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

Greetings, Dear Hive Learners community member a warm welcome to you in the 29th lecture of the Android App Development series. We have already worked on signing signup and the welcome screen./ But sometimes we just need to show a progress bar to the end user to execute some data in the background. Meanwhile, we will show a progress dialog. We can stop this dialog on task completion or new can show it for specific time intervals.

GitHub Link

Use this GitHub project to clone into your directory. It will constantly get updated in the following lecture so you will never miss the latest code. Happy Coding!.

What Should I Learn

  • How to create ProgressDialog
  • How to use the Handler

Assignment

  • Show a ProgressDialg for 3 seconds.

Procedure

  • First, we need to declare and initialize the progress dialog. I am using the Welcome activity for this. We will also set the message that will show in the progress dialog by using its setMessage method. we can also change it later.

I want to show the Progress Dialog for 2 seconds so I am going to use a handler that will run the time and after 2 seconds the ProgressDialog will automatically hide.

Now first we need to show the Progress Dialog and then after 2 seconds, we will cancel it with the help of a handler. We will write the cancel code in the run method of the handler. We also check if the Progress Dialog is on the screen or not. If we do not check it then it can result in some error that we can cancel a progress dialog that is not showing.

        progressDialog.show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (progressDialog.isShowing()) {
                    progressDialog.cancel();
                }

            }
        }, 2000);

Now let's run the app and check if it is working or not.


hl_divider.png

Thank You

hl_footer_banner.png



0
0
0.000
5 comments
avatar

Thanks for another chapter!
!1UP

You can earn passive income by delegation of tribe tokens to "The Cartel".

dlmmqb-TheCartel-banner
Click this banner to join "The Cartel" discord server to know more.

0
0
0.000
avatar

Thank you so much for this edition. I have learnt some new things here

0
0
0.000