我有多个读取查询。
Query query = QueryOperations
.field("deleted").eq(false)
.select("title", "price", "district","anouncement_id")
.orderBy("announce_from", QueryOrder.Descending)
.skip(countIsLoaded) // counter
.top(5);
另一个是或ecc ..
Query query = QueryOperations
.field("deleted").eq(false)
.orderBy("created", QueryOrder.Descending)
.skip(countIsLoaded) // counter
.top(5);
我将不得不使用Andriod异步任务进行查询。 现在我有多个asyntask因为我没有找到传递Azure Mobile Service查询的方法。这是我目前的代码
try {
MobileServiceTable<Foo> mToDoTable = MakeEasyApplication.mClient.getTable(Foo.class);
MobileServiceList<Foo> listAnnounce = mToDoTable.where()
.field("deleted").eq(false)
.select("title", "price", "announce_from", "district","anouncement_id")
.orderBy("announce_from", QueryOrder.Descending)
.skip(countIsLoaded)
.top(5)
.execute().get();
for (Foo foo: listAnnounce) {
publishProgress(foo);
}
} catch (Exception e) {
e.printStackTrace();
}
我如何传递查询参数而不是多个异步任务?
答案 0 :(得分:0)
@JoJo,根据我的经验,我认为有两种方法可以为异步任务包装多个查询。
将具有不同查询名称的多个查询换行到函数中。
public Query getQuery(String qName) {
Query query = null;
switch(qName){
case "QN1":
query = QueryOperations
.field("deleted").eq(false)
.select("title", "price", "district","anouncement_id")
.orderBy("announce_from", QueryOrder.Descending)
.skip(countIsLoaded) // counter
.top(5);
break;
case "QN2":
query = QueryOperations
.field("deleted").eq(false)
.orderBy("created", QueryOrder.Descending)
.skip(countIsLoaded) // counter
.top(5);
break;
//......
default:
//......
}
return query;
}
//In async task
Query query = getQuery("<qName>");
MobileServiceTable<Foo> mToDoTable = MakeEasyApplication.mClient.getTable(Foo.class);
MobileServiceList<Foo> listAnnounce = mToDoTable.where().execute(query).get();
使用自定义API,您可以在移动backend中定义自定义API并在Android client中调用自定义API,然后使用自定义API的名称作为参数,而不是具有多个异步任务。