简体   繁体   中英

How to get Asynctasks to update a different activity than it was launched from

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM