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

What is Android

Android is a moblie operating System that is based on a modified version of Linux. It was originally developed by a startup of the same name , Android , Inc. In 2005 , as part of its strategy to enter the moblie space , Google purchased Android , Inc. and took over its development work (as well as its development team). Google wanted the Android OS to be open and free , so most of the Android code was released under the open source Apache License. That means anyone who wants to use Android can do so by downloading the full Android source code. Moreover, vendors ( typically hardware manufacturers ) can add their own proprietary extensions to Android and customize Android to differentiate their products from others . This development model makes Android very attractive to vendors, especially those companies affected by the phenomenon of Apple's iPhone,which was a hugely successful product that revolutionized the smartphone industry. When the iPhone was launched , many smartphone m...

Android Studio

The first and most important piece of software you need to download is Android Studio. After you have downloaded and installed Android Studio , you can use the SDK Manager to download and install multiple versions of the Android SDK. Having multiple version of the SDK available enables you to write programs that target different devices. For example , you can write one version of an application that specifically targets Android Nougat , but because that flavor Android is on less than 1% of devices, with multiple versions of the SDK you can also write a version of your app that uses older features and targets Marshmallow or Lollipop users. You can use Android Device Manager to set up device emulators. You can Download Android Studio from https://developer.android.com/studio Android Studio is packaged in an executable. Run the install process to set up Android Studio. After you've download and run the setup executable, use the following steps to go through the installation proce...

Creating Android Virtual Devices (AVDs)

The next step is to create an Android Virtual Device (AVD) you can use for testing your Android application. An AVD is an emulator instance that enables you to model an actual device. Each AVD consists of a hardware profile ; a mapping to a system image ; and emulated storage,such as a secure digital (SD) card.One important thing to remember about emulators is that they are not perfect. There are some applications , such as games (which are GPU heavy ) or application that use sensors such as the GPS or accelerometer. Theses types of application cannot be simulated with the same speed or consistency within an emulator as they can when running on an actual device. However , the emulator is good for doing some generalized testing of your applications. You can create as many AVDs as you want to test your applications with different configurations. This testing is important to confirm the behavior of you application when it is run on different devices with varying capabilities. Use ...