如何在 Android 的工作线程上获得 运行 的不确定进度条?

How do you get an indeterminate progress bar to run on a worker thread on Android?

我有以下代码:

        <ProgressBar
            android:id="@+id/progress_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/learning_directions_label"
            android:indeterminate="true"
            android:layout_margin="10dp"
            />

但我不确定输出是在 UI 线程上运行还是在工作线程上运行 w/o 添加了任何逻辑?我怎么能把它放在工作线程上?

ProgressBar 本身在 UI 线程上进行动画处理,无需进一步干预。

如果您想将 ProgressBar 与您想做的某些工作联系起来,请使用 AsyncTask

执行以下操作
new AsyncTask<Void, Void, Void> () {
    @Override
    protected void onPreExecute(Void aVoid) {
        // make your ProgressBar visible here, this runs on UI Thread
    }

    @Override
    protected Void doInBackground(Void... voids) {
        // do your work here, this runs on BG thread
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        // hide your Progress bar here, this runs on UI thread
    }
}.execute();