Adding UI elements
Now we can start adding some UI elements to do some testing. First, let's update the layout of MainActivity
, which is located in res/layout/activity_main.xml.
For now, just adding a ProgressBar
will do, so let's replace the contents of the ConstraintLayout
so that a ProgressBar
is located in the middle of the screen:
<android.support.constraint.ConstraintLayout ...> <ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout>
By running the application, you will now only see the circular progress bar infinitely spinning. Let's use that spinner to see how the wrong handling of threads can affect the UI.