Order of Operations in android, why are so going on?

I have a strange problem with the order of execution methods. A progress bar.setVisibility(View.VISIBLE)appears only after the operation geocoder.getFromLocation is end.

summarizing:

  • first is 60 sec geocoder.getFromLocation
  • after the download I see progressWheel.setVisibility

my expectations:

Firstly, I want to see progress , later start time-consuming operations

void doSomethingTimeConsuming()
{
   progressWheel.setVisibility(View.VISIBLE);
   for(int i=0;i<100;++i)
   {
       List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
       progressWheel.setProgress(i);
   {
}

program must be running on the main thread without thread

Yes, of course I know that I should not do so in the main thread, I ask because I'm curious about why there was such a strange situation, I would like to understand better to avoid such of situations in the future.

Jon Skeet
people
quotationmark

program must be running on the main thread without thread

Well that's the problem. You're performing an expensive operation (getFromLocation) on the UI thread. Don't do that, basically. You're stopping the UI from being updated because the UI thread is busy calling getFromLocation.

You should use another thread for this operation - marshalling back to the UI thread where appropriate to update the UI.

people

See more on this question at Stackoverflow