Skip to main content

Showing a Progress Dialog

    

One normal UI highlight in an Android gadget is the "Please wait" exchange that you ordinarily observe when an application is playing out a long-running errand. For instance, the application may be signing in to a worker before the client is permitted to utilize it, or it very well may be doing a computation prior to showing the outcome to the client. In such cases, it is useful to show a discourse, known as a progress dialog, with the goal that the client is kept on top of it.

 

Displaying a Progress Dialog (Please Wait):-

 

1.Manifest File

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.jfdimarzio.activity101">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@android:style/Theme.Material">    
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>        
        </activity>    
    </application>   
</manifest>
 

2.MainActivity.java file:        

package com.android.activity101; 
import android.app.Activity; 
import android.app.ProgressDialog; 
import android.os.CountDownTimer; 
import android.os.Bundle; 
 
public class MainActivity extends Activity { 
    ProgressDialog progressDialog;
    @Override protected void onCreate(Bundle savedInstanceState) 
    { 
         super.onCreate(savedInstanceState);                                                setContentView(R.layout.activity_main); 
    }
         
    public void onStart() 
    {
         super.onStart(); 
         progressDialog = ProgressDialog.show(this,"Please Wait", "Processing...",true); 
         CountDownTimer timer = new CountDownTimer(3000,1000) 
         { 
            @Override 
            public void onTick(long millisUntilFinished) 
            { 
            } 
            @Override 
            public void onFinish() 
            { 
                progressDialog.dismiss(); 
            } 
        }.start(); 
    }
    

3.Press Shift+F9 to investigate the application on the Android emulator. You see the improvement exchange. It vanishes following three seconds.

How It Works

To make an progress dialog, you make an example of the ProgressDialog class and call its show()method:


progressDialog = ProgressDialog.show(this,"Please Wait", "Processing...",true);

This shows the advancement exchange. Since this is a modular exchange, it will impede the UI until it is excused. To close the exchange, you make a clock that calls the excuse() technique following three seconds.

CountDownTimer timer = new CountDownTimer(3000,1000) {
    @Override
    public void onTick(long millisUntilFinished) {
    }
    @Override
    public void onFinish() {
        progressDialog.dismiss();
    }
}.start();  
 

After the three seconds have slipped by, you excuse the discourse by calling the excuse() technique.    

 

The following segment clarifies utilizing Intents, which assist you with exploring different Activities.

 

 

Comments

Popular posts from this blog

Hiding the Activity Title

You can also hide the title of an activity if desired ( Such as when you just want to display a status update to the user). To do so , use the requestWindowFeature() method and pass it the window .FEATURE_NO_TITLE constant, like This : import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Window; public class MainActivity extends AppCompatActivity{            @Override            protected void onCreate ( Bundle savedInstanceState )            {                         super.onCreate (savedInstanceState );                         setContentView (R.layout.activity_main);                         requestWindowFeature(Window.FEATURE_NO_TITLE);             } } Now you need change the theme in the AndoirdManifest.xml to a theme that has no title bar. Be sure to change all instances of "com.android" to whatever.package name your project is using. package com.android.activity101; <?xml version="1.0" encoding=

OBTAINING THE REQUIRED TOOLS

Now that you know what Android is and what its feature set contains, you are probably anxious to get your hands dirty and start writing some application! Before you write your first app,however , you need to download the required tools. For Android development , you can use a Mac,Windows PC,or a Linux machine. You can freely download all the necessary tools. Most of the examples provided in the blog are written to work on Android Studio. For this Blog, i am using a Windows 10 computer to demonstrate all the code samples.If you are using a Mac or Linux computer , the screenshots look similar. Some minor differences might be present,but you should be able to follow along without problems. Let the fun begin ! NOTE:- The Android Studio makes use of the Java SE Development Kit (JDK) . If Your computer does not have JDK installed, yous should by Downloading it from https://www.oracle.com/technetwork/java/javase/downloads/jdk13-downloads-5672538.html and installing it prior to movin