In the design idea of Android, in order to ensure the user smooth operation experience. Some time-consuming tasks cannot be run in the UI thread, such as accessing the network. So we have to re-open a background thread to run these tasks. However, these tasks often end up needing to access and control the UI controls directly or indirectly. For example, access to the network to obtain data, and then need to display these data processing. The above-mentioned situation arises. This is a normal phenomenon, but Android rules that no other thread can access and manipulate the UI controls other than the UI thread. In order to solve this problem, it leads to our topic today. How background threads in Android interact with the UI thread.
As far as I know, Android provides the following methods to enable background threads to interact with the UI thread.
1, Handler
2, Activity.runonuithread (Runnable)
3, View.post (Runnable)
4, view.postdelayed (Runnabe,long)
5, Asynctask
6, Broadcastreciver
6 ways that UI threads in Android interact with background threads design