与进度活动 - >服务 - > AsyncTask的下载 - 但如何更新进度? [英] Activity with ProgressBar -> Service -> AsyncTask for downloading - but how to update the progress?
问题描述
这是当前状态/情况:我有一个活动结合创造AsyncTasks它下载各种网络资源的服务。效果很好,但当然的进度条显示什么。
this is the current state/situation: I have an Activity which binds a Service which creates AsyncTasks which downloads various web resources. That works well, but of course the ProgressBar shows nothing.
previously我有它创建了下载的一些东西,一个AsyncTask的一个活动。该AsyncTask的得到它保存进度栏查看。所以我可以更新使用onProgressUpdate和publishProgress的进展。很显然,因为我没有提及进度,这并不正常工作下去了。
Previously i had an Activity which created an AsyncTask which downloaded some stuff. The AsyncTask got the View which holds the ProgressBar. So i could update the progress using onProgressUpdate and publishProgress. Obviously this doesn't work any longer because I have no reference to the ProgressBar.
那么,你有没有关于如何更新的进展?任何想法
So, do you have any idea on how to update the progress?
在此先感谢。
推荐答案
有服务
通知,然后运行活动
有关从 onProgressUpdate进度()
。这可能是通过广播意图
,或通过由活动
注册一个回调对象(和未注册的时候,活动
被破坏,如屏幕旋转)。
Have the Service
notify the then-running Activity
about the progress from onProgressUpdate()
. That could be via a broadcast Intent
, or via a callback object registered by the Activity
(and unregistered when the Activity
is destroyed, such as on a screen rotation).
这篇关于与进度活动 - >服务 - > AsyncTask的下载 - 但如何更新进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!