Use AsyncTask and do invalidate () with your layout inside onPostExecute (). All user interface drawings are executed as soon as your control returns to the user interface manager when you return from your code. It is not possible to force redrawing without exiting the code, so people use AsyncTask or Handlers to do this.
My example:
// this goes inside your OnCreate don't use OnResume or you need to start // your service each time apk resumes?? in that case put it inside // OnStart()<
If you analyze the programming pattern that I set above, you will see that it is not difficult. Whenever you need to update the user interface, you need to think that the stream is like this -> mycode () - Ui manager - mycodepart2 (), you need to break your code into two pieces, returning first to the UI manager and continuing in piece two.
The problem is that you have no control over how to execute piece two after exiting to the interface manager, so AsyncTask works well, PreExecute () do chunk1, PostExecute () does piece 2. Both parts execute inside the user interface thread, you can update any user interface. doInBackground () is its other kind of animal, executed in its own thread and cannot update the interface.
ruhalde
source share