- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在我的 Android 应用程序中,我有 3 个 Activity 供用户填写个人资料并注册:
我能够传递 ParseUser 对象并将用户输入保存在 Parse 的第一个 Activity 和第二个 Activity 中。但是,在第三个 Activity 中,我无法在 Parse 上保存 PIN 码和密码。我使用 Log.d 检查用户 ID,它对所有 3 个 Activity 都是相同的,而且 Pins 和密码字段都有值。我只是不明白为什么我不能使用 ParseUser 对象中的 saveInBackground 在上一个 Activity 中保存 Pins 和密码。我想知道是否有专家可以帮助我解决这个问题。非常感谢。
第一次注册 Activity : 公共(public)类 RegisterActivity 扩展 Activity {
protected EditText mFirstName;
protected EditText mMiddleName;
protected EditText mLastName;
protected EditText mUserEmail;
protected EditText mPhoneNumber;
protected EditText mAddressLine1;
protected EditText mAddressLine2;
protected EditText mEmergencyName;
protected EditText mEmergencyPhone;
protected EditText mEmergencyRelationship;
protected EditText mEmergencyOtherInfo;
protected Button mNextPageButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
//Parse.enableLocalDatastore(this);
Parse.initialize(this, "XXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXX");
//Initialize
mFirstName = (EditText)findViewById(R.id.firstNameRegisterEditText);
mMiddleName = (EditText)findViewById(R.id.middleNameRegisterEditText);
mLastName = (EditText)findViewById(R.id.lastNameRegisterEditText);
mUserEmail = (EditText)findViewById(R.id.emailRegisterEditText);
mPhoneNumber = (EditText)findViewById(R.id.phoneRegisterEditText);
mAddressLine1 = (EditText)findViewById(R.id.addressRegisterText);
mAddressLine2 = (EditText)findViewById(R.id.address2RegisterText);
mEmergencyName = (EditText)findViewById(R.id.emergencyNameEditText);
mEmergencyPhone = (EditText)findViewById(R.id.emergencyPhoneEditText);
mEmergencyRelationship = (EditText)findViewById(R.id.emergencyRelationshipEditText);
mEmergencyOtherInfo = (EditText)findViewById(R.id.medicalInfoEditText);
mNextPageButton = (Button)findViewById(R.id.nextPageButton);
//Listen to register button click
mNextPageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Get first name, middle name, last name, user email, phone number, address line 1, address line 2,
//emergency name, emergency phone, emergency relationship, emergency other info and convert them to string
String firstName = mFirstName.getText().toString().trim();
String middleName = mMiddleName.getText().toString().trim();
String lastName = mLastName.getText().toString().trim();
String userEmail = mUserEmail.getText().toString().trim();
String phoneNumber = mPhoneNumber.getText().toString().trim();
String addressLine1 = mAddressLine1.getText().toString().trim();
String addressLine2 = mAddressLine2.getText().toString().trim();
String emergencyName = mEmergencyName.getText().toString().trim();
String emergencyPhone = mEmergencyPhone.getText().toString().trim();
String emergencyRelationship = mEmergencyRelationship.getText().toString().trim();
String emergencyOtherInfo = mEmergencyOtherInfo.getText().toString().trim();
//String password = mUserPassword.getText().toString().trim();
final ParseUser user = new ParseUser();
//Store user in parse
user.put("firstName", firstName);
user.put("middleName", middleName);
user.put("lastName", lastName);
user.put("email", userEmail);
user.put("phoneNumber", phoneNumber);
user.put("addressLine1", addressLine1);
user.put("addressLine2", addressLine2);
user.put("emergencyName", emergencyName);
user.put("emergencyPhone", emergencyPhone);
user.put("emergencyRelationship", emergencyRelationship);
user.put("otherInfo", emergencyOtherInfo);
user.put("username", userEmail);
//Store empty values for username, password, and email because the signUpInBackground requires these fields
//We will actually add these values in later
user.setUsername(userEmail);
user.setEmail(userEmail);
user.setPassword("");
//Need to call Signup first
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(ParseException e) {
if (e == null){
//Saved successfully
//Passing user object to AppearanceActivity and take user to appearance register page
Intent intent = new Intent(RegisterActivity.this, AppearanceActivity.class);
intent.putExtra("user_id", user.getObjectId());
startActivity(intent);
} else {
//Save failed
Log.d("", "User update error: " + e);
}
}
});
}
});
}
}
第二次出现 Activity
public class AppearanceActivity extends Activity {
protected EditText mEthnicity;
protected EditText mHeight;
protected EditText mWeight;
protected EditText mHairColor;
protected EditText mEyeColor;
protected EditText mBirthday;
protected EditText mGender;
protected Button mNextPageButtonOnAppearance;
String userId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_appearance);
//Receiving
Intent intent = getIntent();
//assigns data that was passed from previous activity.
userId = intent.getExtras().getString("user_id");
Log.d("Kiem", "userID is: " + userId);
//sets variables to their respective xml elements.
mEthnicity = (EditText)findViewById(R.id.ethnicityEditText);
mHeight = (EditText)findViewById(R.id.heightNumberPicker);
mWeight = (EditText)findViewById(R.id.weightEditText);
mHairColor = (EditText)findViewById(R.id.hairEditText);
mEyeColor = (EditText)findViewById(R.id.eyeEditText);
mBirthday = (EditText)findViewById(R.id.birthdayDatePicker);
mGender = (EditText)findViewById(R.id.genderEditText);
mNextPageButtonOnAppearance = (Button)findViewById(R.id.nextPageButtonOnAppearance);
//Listen to Next Page button to click
mNextPageButtonOnAppearance.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//Get ethnicity, height, weight, hair color, eye color, birthday, gender and covert them to string
final String ethnicity = mEthnicity.getText().toString().trim();
final String height = mHeight.getText().toString().trim();
final String weight = mWeight.getText().toString().trim();
final String hairColor = mHairColor.getText().toString().trim();
final String eyeColor = mEyeColor.getText().toString().trim();
String birthday = mBirthday.getText().toString().trim();
final String gender = mGender.getText().toString().trim();
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("objectId", userId);
// Execute the query to find the object with ID
query.getInBackground(userId, new GetCallback<ParseUser>() {
public void done(final ParseUser user, ParseException e) {
if (e == null) {
user.put("ethnicity", ethnicity);
user.put("hairColor", hairColor);
user.put("eyeColor", eyeColor);
user.put("gender", gender);
user.put("height", height);
user.put("weight", weight);
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if(e == null){
//Saved successfully
//Passing user object to PinsActivity and take user to Pins register page
Intent intent = new Intent(AppearanceActivity.this, PinsActivity.class);
intent.putExtra("user_id", user.getObjectId());
startActivity(intent);
} else {
//Save failed
Log.d("", "User update error: " + e);
}
}
});
} else {
//Log.d("Kiem", "Error: " + e.getMessage());
}
}
});
}
});
//AlertDialog with list view to select ethnicity
public void alertEthnicityListView(View view){
final CharSequence[] ethics = {"Caucasian", "African American", "Asian", "Hispanic", "Middle-Eastern/Indian","Native American","Other"};
AlertDialog.Builder builder = new AlertDialog.Builder(AppearanceActivity.this);
builder.setTitle("Select your ethinicity");
builder.setItems(ethics, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int ethic) {
mEthnicity.setText(ethics[ethic]);
}
}).show();
}
//AlertDialog with list view to select hair color
public void alertHairListView(View view){
final CharSequence[] hairs = {"Brown", "Black", "Blonde", "Red", "Strawberry-Blonde", "Dirty-Blonde", "Dyed-Pink", "Dyed-Blue", "Dyed-Green", "Dyed-Purple", "Dyed-Red"};
AlertDialog.Builder builder = new AlertDialog.Builder(AppearanceActivity.this);
builder.setTitle("Select your hair color");
builder.setItems(hairs, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int hair) {
mHairColor.setText(hairs[hair]);
}
}).show();
}
//AlertDialog with list view to select eye color
public void alertEyeListView(View view){
final CharSequence[] eyes = {"Green", "Blue", "Hazel", "Brown", "Amber", "Other"};
AlertDialog.Builder builder = new AlertDialog.Builder(AppearanceActivity.this);
builder.setTitle("Select your eye color");
builder.setItems(eyes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int eye) {
mEyeColor.setText(eyes[eye]);
}
}).show();
}
//AlertDialog with list view to select gender
public void alertGenderListView(View view){
final CharSequence[] genders = {"Male", "Female"};
AlertDialog.Builder builder = new AlertDialog.Builder(AppearanceActivity.this);
builder.setTitle("Select your gender");
builder.setItems(genders, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int gender) {
mGender.setText(genders[gender]);
}
}).show();
}
//AlertDialog with list view to select birthday
Calendar myCalendar = Calendar.getInstance();
DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
};
private void updateLabel() {
String myFormat = "MM/dd/yy"; //In which you need put here
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
mBirthday.setText(sdf.format(myCalendar.getTime()));
}
}
第三针 Activity
public class PinsActivity extends Activity {
protected EditText mPassword;
protected EditText mConfirmPassword;
protected Button mRegisterButton;
protected EditText mPin;
protected EditText mFakePin;
String userId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pins);
//Receiving
Intent intent = getIntent();
//assigns data that was passed from previous activity.
userId = intent.getExtras().getString("user_id");
Log.d("Kiem2", "userID is: " + userId);
//sets variables to their respective xml elements.
mPassword = (EditText)findViewById(R.id.passwordEditText);
mConfirmPassword = (EditText)findViewById(R.id.confirmPasswordEditText);
mRegisterButton = (Button)findViewById(R.id.registerButton);
mPin = (EditText)findViewById(R.id.pinEditText);
mFakePin = (EditText)findViewById(R.id.fakePinEditText);
//Force soft keyboard to appear for user to type in password and confirm password
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mPassword, InputMethodManager.SHOW_IMPLICIT);
imm.showSoftInput(mConfirmPassword, InputMethodManager.SHOW_IMPLICIT);
//Listen to Register Button to click
mRegisterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("Kiem3", "userID is: " + userId);
signup();
}
});
}
private void signup(){
//get values for password, confirm password, pin, fake pin fields and convert them to strings
final String password = mPassword.getText().toString();
final String confirmPassword = mConfirmPassword.getText().toString();
final String pin = mPin.getText().toString().trim();
final String fakePin = mFakePin.getText().toString().trim();
Log.d("Value of fakepin ", "is: " + fakePin);
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("objectId", userId);
// Execute the query to find the object with ID
query.getInBackground(userId, new GetCallback<ParseUser>() {
public void done(final ParseUser user, ParseException e) {
if (e == null) {
user.put("password", password);
user.put("pin", pin);
user.put("fakePin", fakePin);
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
// Saved successfully.
//Passing user object to AppearanceActivity and take user to appearance register page
Intent intent = new Intent(PinsActivity.this, MainActivity.class);
intent.putExtra("user_id", user.getObjectId());
startActivity(intent);
} else {
// The save failed.
Log.d("", "User update error: " + e);
}
}
});
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_LONG).show();
} else {
//Log.d("Kiem", "Error: " + e.getMessage());
}
}
});
//Check if password and confirm password fields are not blank and that they're matched
boolean validationError = false;
StringBuilder validationErrorMessage = new StringBuilder(getString(R.string.error_intro));
if (password.length() == 0) {
if (validationError) {
validationErrorMessage.append(getString(R.string.error_join));
}
validationError = true;
validationErrorMessage.append(getString(R.string.error_blank_password));
}
if (!password.equals(confirmPassword)) {
if (validationError) {
validationErrorMessage.append(getString(R.string.error_join));
}
validationError = true;
validationErrorMessage.append(getString(R.string.error_mismatched_passwords));
}
validationErrorMessage.append(getString(R.string.error_end));
//Append validationErrorMessage with the appropriate error strings as well as set validationError as errors are detected
if (validationError) {
Toast.makeText(PinsActivity.this, validationErrorMessage.toString(), Toast.LENGTH_LONG).show();
return;
}
}
}
最佳答案
我通过使用 bundle 传递数据然后在最后一个 Activity 将数据上传到 Parse 解决了这个问题。谢谢你。
关于Android - 在 Activity 之间传递 ParseUser 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28616042/
我的一位教授给了我们一些考试练习题,其中一个问题类似于下面(伪代码): a.setColor(blue); b.setColor(red); a = b; b.setColor(purple); b
我似乎经常使用这个测试 if( object && object !== "null" && object !== "undefined" ){ doSomething(); } 在对象上,我
C# Object/object 是值类型还是引用类型? 我检查过它们可以保留引用,但是这个引用不能用于更改对象。 using System; class MyClass { public s
我在通过 AJAX 发送 json 时遇到问题。 var data = [{"name": "Will", "surname": "Smith", "age": "40"},{"name": "Wil
当我尝试访问我的 View 中的对象 {{result}} 时(我从 Express js 服务器发送该对象),它只显示 [object][object]有谁知道如何获取 JSON 格式的值吗? 这是
我有不同类型的数据(可能是字符串、整数......)。这是一个简单的例子: public static void main(String[] args) { before("one"); }
嗨,我是 json 和 javascript 的新手。 我在这个网站找到了使用json数据作为表格的方法。 我很好奇为什么当我尝试使用 json 数据作为表时,我得到 [Object,Object]
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我听别人说 null == object 比 object == null check 例如: void m1(Object obj ) { if(null == obj) // Is thi
Match 对象 提供了对正则表达式匹配的只读属性的访问。 说明 Match 对象只能通过 RegExp 对象的 Execute 方法来创建,该方法实际上返回了 Match 对象的集合。所有的
Class 对象 使用 Class 语句创建的对象。提供了对类的各种事件的访问。 说明 不允许显式地将一个变量声明为 Class 类型。在 VBScript 的上下文中,“类对象”一词指的是用
Folder 对象 提供对文件夹所有属性的访问。 说明 以下代码举例说明如何获得 Folder 对象并查看它的属性: Function ShowDateCreated(f
File 对象 提供对文件的所有属性的访问。 说明 以下代码举例说明如何获得一个 File 对象并查看它的属性: Function ShowDateCreated(fil
Drive 对象 提供对磁盘驱动器或网络共享的属性的访问。 说明 以下代码举例说明如何使用 Drive 对象访问驱动器的属性: Function ShowFreeSpac
FileSystemObject 对象 提供对计算机文件系统的访问。 说明 以下代码举例说明如何使用 FileSystemObject 对象返回一个 TextStream 对象,此对象可以被读
我是 javascript OOP 的新手,我认为这是一个相对基本的问题,但我无法通过搜索网络找到任何帮助。我是否遗漏了什么,或者我只是以错误的方式解决了这个问题? 这是我的示例代码: functio
我可以很容易地创造出很多不同的对象。例如像这样: var myObject = { myFunction: function () { return ""; } };
function Person(fname, lname) { this.fname = fname, this.lname = lname, this.getName = function()
任何人都可以向我解释为什么下面的代码给出 (object, Object) 吗? (console.log(dope) 给出了它应该的内容,但在 JSON.stringify 和 JSON.parse
我正在尝试完成散点图 exercise来自免费代码营。然而,我现在只自己学习了 d3 几个小时,在遵循 lynda.com 的教程后,我一直在尝试确定如何在工具提示中显示特定数据。 This code
我是一名优秀的程序员,十分优秀!