问题
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