Android – Showing activity indicator in android


I am new to android.I need to show an activity indicator while synchronizing.On clicking a button,i am redirecting to a new activity.In this new activity i am synchronizing.I need to show an activity indicator on button click till it is synchronized.

Best Solution

Synchronizing is effectively a network task And you have to do this on Background ( Async Task) So you can call an AsyncTask in your new Activity

private class SyncOperation extends AsyncTask<String, Void, String> {

      ProgressDialog progressDialog;

      protected String doInBackground(String... params) {

          // Synchronize code here

             return null;

      protected void onPostExecute(String result) {   
                    if (progressDialog.isShowing()) {

      protected void onPreExecute() {
                     if (progressDialog == null) {
                    progressDialog = new ProgressDialog(MainActivity.this);
                    progressDialog.setMessage("Synchronizing, please wait...");


Now in OnCreate() of new Activity

SyncOperation syncTask=new SyncOperation();

It will show a loader like

enter image description here