如何获得Asynctasks更新比它从推出不同的活动 [英] How to get Asynctasks to update a different activity than it was launched from
问题描述
我有一个启动一个的AsyncTask的熄灭,下载和数据的processess很多的闪屏的活动。这需要一段时间(20ish秒),它是数据的刷新,所以我不等待它,所以送我的用户主要活动在那里他们可以查看最近的缓存数据(与指标数据仍然在下载)。
I have an Splash Screen activity that launches an Asynctask that goes off and downloads and processess alot of data. It takes a while (20ish seconds) and it's a refresh of data so I dont wait for it and so send my users to a main activity where they can view the last cached data (with an indicator data is still downloading).
什么是异步任务通知主活性(或任何其它当前活动用户正在观看),它的完成,并刷新屏幕和停止指示符的最佳方式(或任何方式)?
What is the best way (or any way) for the async task to notify the main activity (or any other current activity the user is viewing) that its done and to refresh screen and stop the indicator?
仅供参考,我不希望只是推出的AsyncTask从主因为有一些用户可能浏览到所有需要知道什么时候完成,并停止显示该指标。另外3 activitys
FYI, I dont want to just launch the AsyncTask from the Main as there are 3 other activitys that the user may have navigated to that all would need to know when it is done and to stop showing the indicator.
推荐答案
您的AsyncTask
可以播放的意图
时,数据是可用的。当前活动可以建立一个监听器为广播意图
键,刷新屏幕时,它得到它。
Your AsyncTask
can broadcast an Intent
when the data is available. The current Activity can set up a listener for that broadcast Intent
and refresh the screen when it get it.
这篇关于如何获得Asynctasks更新比它从推出不同的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!