使用Azure移动服务Android SDK检索超过50行

时间:2015-01-14 09:17:56

标签: android azure azure-mobile-services

我通常在表格中有超过50行,我想从Azure移动服务返回到我的Android应用程序,我创建了以下函数来下载整个表格:

private void genericPagedLoad(final int count, final Query baseQuery, final MobileServiceSyncTable table) {
new AsyncTask<Void, Void, Void>() {
    @Override
    protected Void doInBackground(Void... params) {
        int takenCount = 0;
        int top = 50;
        while (takenCount < count) {
            Query query = baseQuery.skip(takenCount).top(top);
            try {
                table.pull(query).get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
            takenCount += top;
        }
        return null;
    }
}.execute();

}

我打电话给

ListenableFuture<MobileServiceList<Level>> future = mClient.getTable(Level.class).where().includeInlineCount().execute();
Futures.addCallback(future, new FutureCallback<MobileServiceList<Level>>() {
@Override
public void onSuccess(MobileServiceList<Level> levels) {
    int count = levels.getTotalCount();
    Query q = mClient.getTable(Level.class).where();
    genericPagedLoad(count, q, mLevelTable);
}

@Override
public void onFailure(Throwable throwable) {
}
});

但是,我想以比50更大的数据块下载数据,但如果我将变量top更改为ex。 100它仍然只下载50行然后跳过100行。根据{{​​3}},应该可以使用top()函数(最多1000行)指定行数,但这显然不能正常工作。我使用的是Azure Android SDK 2.0.1-beta。有没有办法让top()函数按指定的方式工作?

1 个答案:

答案 0 :(得分:1)

您可以使用top()函数,如下所示,它将返回超过50行(MAX为1000):

mClient.GetTable(Level.class).where().top(150).execute(...