Reputation: 6552
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:
geocoder.getFromLocation
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.
Upvotes: 0
Views: 171
Reputation: 3150
Your UI thread is blocked on this line:
geocoder.getFromLocation
You should perform it on a different thread(consider execute it using handler).
Upvotes: 0
Reputation: 1500815
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.
Upvotes: 2