[英]Android - How to get a user's object ID from Parse and store it in a string
I am making a test Sign UP activity for an app that I am planning, and I want to get the user that signed up 's object after the user signs up successfully. 我正在为我正在计划的应用程序进行测试Sign UP活动,并且我希望在用户成功注册后让注册了object的用户获得该用户。 Here's some of my code: 这是我的一些代码:
public void signUp(View v){
String firstNameString = FirstName.getText().toString();
String familyNameString = LastName.getText().toString();
String emailString = email.getText().toString();
if (firstNameString.length()<2){
Context context = getApplicationContext();
CharSequence text = "Your first name must be at least 2 characters";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
if (familyNameString.length()<2){
Context context = getApplicationContext();
CharSequence text = "Your family name must be at least 2 characters";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
if (firstNameString.isEmpty()){
Context context = getApplicationContext();
CharSequence text = "Please Enter a First Name";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
if (familyNameString.isEmpty()){
Context context = getApplicationContext();
CharSequence text = "Please Enter a First Name";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
else {
ParseUser user = new ParseUser();
user.setUsername(firstNameString + familyNameString);
user.setEmail(emailString);
user.setPassword("null");
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
Context context = getApplicationContext();
CharSequence success = "Sign up Successfull";
int duration = Toast.LENGTH_LONG;
Toast successfullTostConformation = Toast.makeText(context,success,duration);
successfullTostConformation.show();
}
else {
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
Context context = getApplicationContext();
CharSequence success = "Sign up failed. Check your internet connection";
int duration = Toast.LENGTH_LONG;
Toast successfullTostConformation = Toast.makeText(context,success,duration);
successfullTostConformation.show();
}
}
});
}
}
That's my onclick listener for the sign up button. 那是我的注册按钮的onclick监听器。 So, as I said, how do I get the user's Object ID, store it in a string, and then save it locally. 因此,正如我所说,如何获取用户的对象ID,将其存储在字符串中,然后将其保存在本地。 I've tried for the first step: 我已经尝试了第一步:
String userID = user.getObjectID
However I have an error under user.getObjectID();
但是我在user.getObjectID();
下有一个错误user.getObjectID();
Variable 'user' is accessed from within inner class, needs to be declared final 从内部类内部访问变量“用户”,需要声明为最终变量
Edit: Oh. 编辑:哦。 I had to put String userID = user.getObjectID
under ParseUser user = new ParseUser();
我必须将String userID = user.getObjectID
放在ParseUser user = new ParseUser();
. 。 Thanks to anyone who tried to help 感谢任何尝试提供帮助的人
Oh. 哦。 I had to put String userID = user.getObjectID
under ParseUser user = new ParseUser();
我必须将String userID = user.getObjectID
放在ParseUser user = new ParseUser();
. 。 Thanks to anyone who tried to help 感谢任何尝试提供帮助的人
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.