固定实时项(子类ParseObject)并立即通过fromPin(pinName)检索 - 列表为空

时间:2015-06-23 22:28:59

标签: android parse-platform

我有一个非常简单的片段,基本上调用一个方法,尝试从互联网上检索自定义Parse对象,固定它们然后重新加载带有固定项目的UI ListView,无论互联网呼叫是否成功(因此有一个后备在没有互联网连接的情况下缓存机制。)

以下是两个关键方法:

// This is called in onViewCreated() and onResume() of the fragment
private void reloadWalletsFromInternet() {
    ParseQuery<Wallet> queryLiveData = ParseQuery.getQuery(Wallet.class);
    queryLiveData.findInBackground(new FindCallback<Wallet>() {
        @Override
        public void done(final List<com.hasmobi.money.models.Wallet> list, ParseException e) {
            if (list != null && list.size() > 0) {
                for (final Wallet w : list) {
                    w.pinInBackground("wallets", new SaveCallback() {
                        @Override
                        public void done(ParseException e) {
                            reloadWalletsFromLocalstore();
                        }
                    });
                }

            } else {
                Log.d(getClass().getSimpleName(), "no wallets retrieved from internet");
                reloadWalletsFromLocalstore();
            }
        }
    });
}

private void reloadWalletsFromLocalstore() {
    final ParseQuery<Wallet> queryLocalData = ParseQuery.getQuery(Wallet.class);

    queryLocalData.fromLocalDatastore();
    queryLocalData.fromPin("wallets");

    queryLocalData.findInBackground(new FindCallback<Wallet>() {
        @Override
        public void done(List<Wallet> list, ParseException e) {

            // Here I am receiving 0 items in "list" which is wrong
            // (e is "null")
        }
    });
}

在App.java内部(我的自定义应用程序基类)我已经将Wallet类子类化为在Parse中注册:

    ParseObject.registerSubclass(Wallet.class);
    Parse.enableLocalDatastore(this);
    Parse.initialize(this, "my keys", "my keys");

我在几个地方放了几条战略Log.d()行,代码成功运行了两个方法,reloadWalletsFromInternet()内的for()循环成功运行,出现将每个收到的电子钱包对象固定在引脚组&#34;钱包&#34;中。但是,由reloadWalletsFromLocalstore()做出的对该组中的图钉的后续查询似乎无法检索这些电子钱包对象。

1 个答案:

答案 0 :(得分:0)

下面的代码将完成这项工作。 摆脱queryLocalData.fromPin("wallets");

private void reloadWalletsFromLocalstore() {
    final ParseQuery<Wallet> queryLocalData = ParseQuery.getQuery(Wallet.class);

    queryLocalData.fromLocalDatastore();


    queryLocalData.findInBackground(new FindCallback<Wallet>() {
        @Override
        public void done(List<Wallet> list, ParseException e) {

            // Here I am receiving 0 items in "list" which is wrong
            // (e is "null")
        }
    });
}