Android

Displaying a Progress Dialog

Google+ Pinterest LinkedIn Tumblr

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

<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. 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;
@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 debug the application on the Android emulator. You see the progress dialog, as shown in It disappears after three seconds.

Write A Comment