Hi.
I need to migrate an Android application developed with the ESRI SDK 10.2.8 to the newest SDK: 100.6.
My first big obstacle is migrating all the queries. Currently, they are done with the object QueryTask (which doesn't exist any longer). With it, I get the response from the server, I send the data with a return to the next step.
Now, it seems that all queries are asynchronous, so the data that is returned is always empty. How can I get a synchronous behaviour with the new SDK? I'm totally stuck.
ArrayList<SPAN class="operator token"><</SPAN>Community<SPAN class="operator token">></SPAN> communities <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">ArrayList</SPAN><SPAN class="operator token"><</SPAN>Community<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
QueryParameters query <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">QueryParameters</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// WHERE</SPAN>
StringBuilder whereStrBuilder <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">StringBuilder</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
whereStrBuilder<SPAN class="punctuation token">.</SPAN><SPAN class="token function">append</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"display_order > 0"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
query<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setWhereClause</SPAN><SPAN class="punctuation token">(</SPAN>whereStrBuilder<SPAN class="punctuation token">.</SPAN><SPAN class="token function">toString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// ORDER </SPAN>
OrderBy order <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">OrderBy</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"display_order"</SPAN><SPAN class="punctuation token">,</SPAN> SortOrder<SPAN class="punctuation token">.</SPAN>ASCENDING<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
query<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getOrderByFields</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">add</SPAN><SPAN class="punctuation token">(</SPAN>order<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
query<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setReturnGeometry</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">false</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">final</SPAN> ListenableFuture<SPAN class="operator token"><</SPAN>FeatureQueryResult<SPAN class="operator token">></SPAN> future <SPAN class="operator token">=</SPAN> Layer<SPAN class="punctuation token">.</SPAN>SERVICE_COMMUNITY<SPAN class="punctuation token">.</SPAN><SPAN class="token function">queryFeaturesAsync</SPAN><SPAN class="punctuation token">(</SPAN>query<SPAN class="punctuation token">,</SPAN> ServiceFeatureTable<SPAN class="punctuation token">.</SPAN>QueryFeatureFields<SPAN class="punctuation token">.</SPAN>LOAD_ALL<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
future<SPAN class="punctuation token">.</SPAN><SPAN class="token function">addDoneListener</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Runnable</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
@Override
<SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">try</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">// check if server result successful</SPAN>
FeatureQueryResult result <SPAN class="operator token">=</SPAN> future<SPAN class="punctuation token">.</SPAN><SPAN class="token function">get</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// check there are some results</SPAN>
Iterator<SPAN class="operator token"><</SPAN>Feature<SPAN class="operator token">></SPAN> resultIterator <SPAN class="operator token">=</SPAN> result<SPAN class="punctuation token">.</SPAN><SPAN class="token function">iterator</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">while</SPAN> <SPAN class="punctuation token">(</SPAN>resultIterator<SPAN class="punctuation token">.</SPAN><SPAN class="token function">hasNext</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
Feature feature <SPAN class="operator token">=</SPAN> resultIterator<SPAN class="punctuation token">.</SPAN><SPAN class="token function">next</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
communities<SPAN class="punctuation token">.</SPAN><SPAN class="token function">add</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">featureToCommunity</SPAN><SPAN class="punctuation token">(</SPAN>feature<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN> e<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">return</SPAN> communities<SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>communities is always empry, because it is returned before the addDoneListener is triggered. Is there a way of making the process wait until the query has finished so the proper list of communities is returned?
Thanks for any help provided!