Displaying a Progress Dialog

1. Using the Activity101 project created earlier in this chapter, make sure you are using the Material theme in the AndroidManifest.xml file. Be sure to change all instances of “com.akbansal” to whatever package name your project is using.

<?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.akbansal.activity101">

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">

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


2. Add the bolded statements from the following code to the MainActivity.java file:

package com.akbansal.activity101; import android.app.Activity;
import android.app.ProgressDialog; import android.os.CountDownTimer; import android.os.Bundle;

public class MainActivity extends Activity {

ProgressDialog progressDialog;
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);


public void onStart()
progressDialog = ProgressDialog.show(this,"Please Wait", "Processing...",true);
CountDownTimer timer = new CountDownTimer(3000,1000) { @Override
public void onTick(long millisUntilFinished) {


public void onFinish() { progressDialog.dismiss();

3. Press Shift+F9 to debug the application on the Android emulator. You see the progress dialog, as shown in It disappears after three seconds.

Leave a Comment