Sometimes, we need to synchronize the actions in a series but not in parallel. For example, we need to download an image then display it on Google Gallery. It seems we cannot display a partial image during downloading. OK, there is another story, probably, we will mention later, for displaying image with a coarse one then detailed the clear picture. Now let’s fix how to download an image then display it, without manual interference.
This program bases on the last one: Programming for Android: Download, Progressbar and FileProvider
Steps:
1. Declare a handler and a message ID, which we need to indicate what action is completed:
1 2 |
|
2. Send out the message, when the first action is completed:
1 2 3 4 |
|
3. Handle the message, then trigger the following action(s):
1 2 3 4 5 6 7 8 9 10 |
|
You can clone the entire source code here [2].
References:
- http://stackoverflow.com/questions/4592716/multithreading-question
- https://github.com/lifuzu/FileProviderExample
Written with StackEdit.