One of the powerful features of Androids is the AsyncTask class.
To work with it, you must first expand it and override doInBackground (...). doInBackground automatically executed in the doInBackground , and you can add some listeners in the user interface thread to receive notification of the status update, these functions: onPreExecute() , onPostExecute() and onProgressUpdate()
You can find an example here.
Refer to the following post for other alternatives:
Handler vs AsyncTask vs Thread
Endian Ogino Jan 18 2018-11-11T00: 00Z
source share