简体   繁体   English

Android-如何从Parse获取用户的对象ID并将其存储在字符串中

[英]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.

相关问题 从字符串中获取android的id资源 - Get android's id resource from a string 如何在 Android Studio 中从没有字符串 ID 的解析 JSON 中获取字符串 - How to Get String From Parse JSON without String Id in Android Studio 如何从 Android 中的 Parse Server 获取字符串 - How to get string from Parse Server in Android 如何从 Firebase Android 中的用户 ID 获取用户 object - How can I get User object from its user id in Firebase Android 如何从Android中的Firebase获取用户ID? - How to get User id from Firebase in android? 如何从Java中的解析中获取字符串而不是获取ID? - How to get string from a parse in java instead of getting id? 从我的 Android 应用中获取用户的电报 ID - Get user's telegram id from my Android app 解析,如何在解析仪表板中存储用户的设备型号? - Parse, how to store user's device model in Parse dashboard? 如何在Android中从Facebook获取用户电子邮件ID和用户名 - How to get user email id , user name from Facebook in android 如何在Android上正确地将联系人的生日从String解析为DateFormat? - How to properly parse a contact's birthday from String to DateFormat on Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM