我有一个非常简单的ParseObject子类 - Wallet
。我正在创建一个新实例并通过saveEventuall()
将其保存到云端,然后立即尝试将其固定到localstore(并最终向我的应用程序广播一个信号,以便它可以更新UI,因为它只从本地存储区读取对象perfrormance。
这是我如何在Application.onCreate()中注册子类:
public void onCreate() {
super.onCreate();
ParseCrashReporting.enable(this);
ParseObject.registerSubclass(Wallet.class); // <----
Parse.enableLocalDatastore(this);
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.initialize(this, "private stuff", "private stuff");
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);
ParseInstallation.getCurrentInstallation().saveInBackground();
if (ParseUser.getCurrentUser() == null)
ParseUser.getCurrentUser().signUpInBackground();
}
这是完整的子类本身:
@ParseClassName("Wallet")
public class Wallet extends ParseObject {
public Wallet() {
}
public void putName(String name) {
put("name", name);
}
public String getName() {
return getString("name");
}
public static ParseQuery<Wallet> getQuery() {
return ParseQuery.getQuery(Wallet.class);
}
}
然后将对象简单保存到云端,将其固定在本地并尝试从引脚检索它以进行测试:
final Wallet c = new Wallet();
c.putName(name);
c.saveEventually(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e != null) e.printStackTrace();
Log.d(getClass().getSimpleName(), c.getObjectId() + " is the saved object id");
c.pinInBackground("wallet", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e != null) e.printStackTrace();
ParseQuery<Wallet> pq = Wallet.getQuery();
pq.fromPin("wallet");
pq.countInBackground(new CountCallback() {
@Override
public void done(int i, ParseException e) {
Log.d(getClass().getSimpleName(), i + " items in pin after saving one");
}
});
}
});
}
});
令我惊讶的是,这就是我在LogCat中看到的内容:
06-29 11:29:00.279: D/(3480): J6ljTKezMf is the saved object id
06-29 11:29:00.303: D/(3480): 0 items in pin after saving one
什么?我刚刚将项目保存到云端然后固定它?为什么引脚组内有0个项目?
思想?
答案 0 :(得分:0)
我相信Parse,ParseObject
类名称区分大小写。在您的代码中,您已获得行pq.fromPin("wallet");
,但您已将类声明为"Wallet"
,因此未返回任何结果。尝试将该行中的"wallet"
更改为"Wallet"
。