Parse subclass for ParseUser Return type

核能气质少年 提交于 2019-12-24 01:14:41

问题


Im subclassing parseUser , so when i look for user i use :

query.getFirstInBackground(new GetCallback<MySubClass>() {

            @Override
            public void done(MySubClass user, ParseException e) {

but when i need to user getCurrentUser or logInInBackground i getting ParseUser instead of MySubClass .

i user this methods :

MySubClass.logInInBackground(userName, "", new LogInCallback() {

    @Override
    public void done(ParseUser u, ParseException arg1) {

    }
});

but i want the callback to return MySubClass object like in my query .

the same with this :

MySubClass.getCurrentUser()

回答1:


Same Problem here.

Actually you can solve this by correctly subclassing your ParseUser.

@ParseClassName("_User")
public class User extends ParseUser {}

Then register your class before initializing parse.

ParseObject.registerSubclass(User.class);

You can then cast to your own subclass without a casting error:

User user = (User)ParseUser.getCurrentUser();



回答2:


As per this article. You actually specifically need to refer to the _User "ParseClassName" when subclassing this object. It's super hairy, I was stuck on this for ages because for other classes you only need to refer to their name as seen in the Parse Data Browser, which in this case is "User", "Info", "Post" etc, but the User class requires the underscore.



来源:https://stackoverflow.com/questions/25530486/parse-subclass-for-parseuser-return-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!