Search code examples
androidandroid-spinner

android loading circle (spinner) between two activity


I have a main activity that has simple buttons and listeners associated to them. Each button opens a new activity (intent). However while opening activity, it takes some time to load which causes an UI freeze. I want to avoid this by simply adding a loading circle (spinner) in between. I've searched many posts but still couldn't find anything.

By loading circle I mean this

image


Solution

  • That is a Progress Bar. You may create this programmatically or by using the widget in XML.

    To implement in XML:

    <ProgressBar
        android:id="@+id/progress_loader"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="visible" />
    

    To implement in Java (using a Progress Dialog as you asked in comments, but you can also do this with the Progress Bar):

     ProgressDialog nDialog;
     nDialog = new ProgressDialog(Login.this);
     nDialog.setMessage("Loading..");
     nDialog.setTitle("Get Data");
     nDialog.setIndeterminate(false);
     nDialog.setCancelable(true);
     nDialog.show();
    

    Before reaching a next activity, you should dismiss() the Progress Bar.

      nDialog.dismiss();