AsyncTask with query

2843
8
Jump to solution
04-04-2013 05:10 AM
MatejSkerjanc
Occasional Contributor
Hello guys

I made an async task that uses featurelayer query. Shouldn't the postExecute be executed when the query has stopped? In my case it doesn't, it executes postExecute then in some time i get query results.

I'm sure there's some logical explanation but since i'm new to android it eludes me.

Can someone explain the basic procedure in this type of task (async task with a callback in the doInBackground)


Thank you in advance guys!
0 Kudos
1 Solution

Accepted Solutions
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
Woa, I missed a big part of your question - You're querying a FeatureLayer.  I wonder if you don't necessarily need to execute your query using an asyncTask as the query is actually performed on the client.
http://help.arcgis.com/en/arcgismobile/10.0/apis/android/api/com/esri/android/map/ags/ArcGISFeatureL...

Is there a specific reason you want to run this as an asyncTask?  I think the query by nature runs asynchronously and the CallbackListener essentially acts as the asyncTask. 
http://help.arcgis.com/en/arcgismobile/10.0/apis/android/api/com/esri/core/map/CallbackListener.html

...
heck out the SelectFeatures sample.  I think it'll help get you pointed in the right direction.

View solution in original post

0 Kudos
8 Replies
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
Do you have any sample code for us to check out?  Are you getting any errors in your LogCat?

Make sure you're returning a FeatureSet from doInBackground to your onPostExecute method.
private class AsyncQueryTask extends AsyncTask<String, Void, FeatureSet> {

protected FeatureSet doInBackground(String... queryParams) {
//execute your query here
}
protected void onPostExecute(FeatureSet result) {
if (result != null) {
//if the query result is not null, do something....
}
}

}
0 Kudos
MatejSkerjanc
Occasional Contributor
This is exactly what i thought i was supposed to do (the postexecute feature set), suprised myself there being an android newbie and all. Thanks sir i'll give it a go and report upon success!


Andrew, i forgot to ask you this

for instance i have
protected FeatureSet doInbackground(Void... params)
{
FeatureSet fs = new FeatureSet();
****query some query******
****fLayer some FeatureLayer******

fLayer.queryFeatures(query, new CallbackListener<FeatureSet>()
{
     private void onCallback(FeatureSet result)
     {
           fs = result;
     }
}



return fs;
}


will doInBackground actually wait till fs is not null or ? I see no other way of doing this
0 Kudos
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
Woa, I missed a big part of your question - You're querying a FeatureLayer.  I wonder if you don't necessarily need to execute your query using an asyncTask as the query is actually performed on the client.
http://help.arcgis.com/en/arcgismobile/10.0/apis/android/api/com/esri/android/map/ags/ArcGISFeatureL...

Is there a specific reason you want to run this as an asyncTask?  I think the query by nature runs asynchronously and the CallbackListener essentially acts as the asyncTask. 
http://help.arcgis.com/en/arcgismobile/10.0/apis/android/api/com/esri/core/map/CallbackListener.html

...
heck out the SelectFeatures sample.  I think it'll help get you pointed in the right direction.
0 Kudos
MatejSkerjanc
Occasional Contributor
well major issue here is i'm trying to envelope querying of like 5 layers but yeah that callback is async byitself it's just i didnt find any nice way to envelope all the work (quite a code, and even not mine) into a nice async package as whole. I'll give it a read thank you for your time you've told me enough i hope.
0 Kudos
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
I'm following you now...  I guess with some work it could be possible.  You could register a callback for each of your 5 queries, and once they have each completed return their results to an array of FeatureSet's (one for each query result) to onPostExecute.  Maybe you can flag each of your queries with boolean values, and once they are all true, move to onPostExecute.  I've never tried, but it might be possible.  Hope that helps.
0 Kudos
MatejSkerjanc
Occasional Contributor
I used the no async approach. Another problem i'm seeing here is that in each callback the coder checks for hasAttachment and then guess what another callback for attachment fetching. It gets more confusing further along the code, because the progress dialog should stay till after all attachments have been downloaded, and ofcourse you don't know how many you even had to begin with. This will require some counters i guess
0 Kudos
MatejSkerjanc
Occasional Contributor
Andrew i think best question for me right now is how can i call postExecute when all attachments have been downloaded from all the features from all the layers
0 Kudos
deleted-user-M6rwsXZZL0Hq
New Contributor

Hi everyone!

I have the same problem, did anyone has a solution? 

Thanks!

0 Kudos