Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为什么DialogFragment中的ProgressBar停止旋转?_Android_Android Dialogfragment - Fatal编程技术网

Android 为什么DialogFragment中的ProgressBar停止旋转?

Android 为什么DialogFragment中的ProgressBar停止旋转?,android,android-dialogfragment,Android,Android Dialogfragment,我的结构如下: 在UIActivity1中: MyMyProgressDialogFragment progressDialog = MyMyProgressDialogFragment.newInstance(); progressDialog.show(getFragmentManager(),"dialog"); getFragmentManager().executePendingTransactions(); ..do some heavy work and send messages

我的结构如下:

在UIActivity1中:

MyMyProgressDialogFragment progressDialog = MyMyProgressDialogFragment.newInstance();
progressDialog.show(getFragmentManager(),"dialog");
getFragmentManager().executePendingTransactions();
..do some heavy work and send messages to progressDialog
将创建对话框片段,该片段中的进度条开始旋转

但当我现在开始创建对话框片段的活动中的繁重工作时,片段中的进度条停止。

当阅读片段文档时,我了解到片段有自己的活动-与Ui活动1相同。而且每个活动都在一个单独的线程中运行

那么,当UIActivity1开始繁重的工作时,为什么对话框片段中的progressbar会停止?

他们不应该是独立的吗

ps当我再次在不同的任务中运行UIActivity之外的繁重工作时,进度条会毫无问题地旋转

我理解这里的错误在哪里


谢谢

从您共享的信息来看还不清楚,但是看起来您正在UI线程中执行所有繁重的任务。这是活动的主线。你的片段附带的活动是否只是为了完成这项工作并不重要,UI线程只能用于更新UI元素,通常避免执行耗时超过100-200毫秒的任务。这是根据android。这可能就是问题所在,任何长期或长期执行的任务都必须在后台线程中完成


看看这个。

哦,你当然是对的。我在wring的假设下,只要DialogFragment在前台,我就可以“滥用”UIActivity来做一些繁重的工作,因为它不需要做任何屏幕更新。好吧,看起来,即使UIActivity不在前台并且没有真正执行任何UI工作,所有其他可见的活动(如片段)也不会更新。谢谢你指出这一点!