I\'ve created activity, which should return array of GeoPoint after user clicked the button. Code which perform http request and parse answer is extracted to AsyncTask. In the <
An AsyncTask
does exactly what it's name suggests - the doInBackground(...)
method runs asynchronously on a separate thread while the code in onCreate(...)
continues to run.
In your code here...
mat.execute(query);
if (overlayList.size() > 0){
tv1.setText("List is OK!");
}
...the if
condition is checked immediately after you call mat.execute(query)
. In other words, your AsyncTask
hasn't had a chance to execute it's doInBackground(...)
method.
Move this code...
if (overlayList.size() > 0){
tv1.setText("List is OK!");
}
...into the onPostExecute(...)
method of your AsyncTask
.
EDIT: As triggs points out in the comment below, calling the get()
method of AsyncTask
will block the main thread and wait for the result to be returned. This effectively makes using an AsyncTask
become a synchronous operation in which case there's no point in using an AsyncTask
.
The only reason I can think of to use the get()
method would be from a thread other than the main (UI) thread although I can't think of many reasons to do that.