Android Activity Indicator?

The most direct equivalent of the iOS Activity Indicator in Android is the ProgressBar but set to indeterminate. So you can drop the view into your layout and it will provide you with a spinning animation.

<ProgressBar
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:id="@+id/ctrlActivityIndicator"
    android:indeterminateOnly="true"
    android:keepScreenOn="true"
     />

You could use this to indicate some background activity to the user.


do some thing like this

ProgressDialog mDialog = new ProgressDialog(getApplicationContext());
            mDialog.setMessage("Please wait...");
            mDialog.setCancelable(false);
            mDialog.show();

public class Mp3cutterActivity extends Activity {

    MP3Class mp3obj = null;
    TextView tv;
    MP3Class mp3classobj = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Context thiscontext = this.getApplicationContext();
        mp3classobj = new MP3Class(thiscontext);
        setContentView(R.layout.main);

        Button btn = (Button)findViewById(R.id.startbutton);
        tv = (TextView)findViewById(R.id.textview1);
        btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                //show a wait indicator as well as the function that calls walkSdcard

                try {
                    new SearchSdCard(Mp3cutterActivity.this).execute();
                    // copyProtector.doCopyProtection();
                } catch (Exception e) {
                    System.out.println("in search SD card  " + e.getMessage());
                }
            }

            private void domp3stuff() {
                // TODO Auto-generated method stub
            }
        });
    }
}

class SearchSdCard extends AsyncTask<String, Void, Boolean> {

    Context context;    

    public ProgressDialog dialog;

    public SearchSdCard(Activity activity) {
        this.context = activity;
    }

    protected void onPreExecute() {
        dialog = new ProgressDialog(context);
        dialog.setMessage("wait for a moment...");
        dialog.show();
    }

    @Override
    protected Boolean doInBackground(String... params) {
        // TODO Auto-generated method stub
        boolean retval = true;
        mp3classobj.searchSdCard();
        return retval;
    }

    @Override
    protected void onPostExecute(Boolean result) {
        // TODO Auto-generated method stub
        if (dialog.isShowing()) {
            dialog.dismiss();
            tv.setText("mp3 cutter is an app which cuts down a chunk of memory \nfrom your sdcard by \ndeleting the .mp3 files and more \nyou were made a BAKRA :-)");
            if(!result){    
                tv.setText("error occured !!");
            }
        }
    }
    //refer below comment for the MP3class.java file details
}

There are two other ways of showing activity indicator without using modal ProgressDialog.

You can use ImageView in your layout and apply animation to it. Refer developer's site.

public void startAnimation() {
  // Create an animation
  RotateAnimation rotation = new RotateAnimation(
      0f,
      360f,
      Animation.RELATIVE_TO_SELF,
      0.5f,
      Animation.RELATIVE_TO_SELF,
      0.5f);
  rotation.setDuration(1200);
  rotation.setInterpolator(new LinearInterpolator());
  rotation.setRepeatMode(Animation.RESTART);
  rotation.setRepeatCount(Animation.INFINITE);

  // and apply it to your imageview
  findViewById(R.id.myActivityIndicator).startAnimation(rotation);
}

Or you can use xml-drawable to describe a background image, which will have some rotating animation:

Firstly describe a drawable (in i.e. /res/drawable/my-indicator.xml)

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/spinner_black_76"
    android:pivotX="50%"
    android:pivotY="50%"
    android:framesCount="12"
    android:frameDuration="100" />

Then set it at some view's background