我创建了两个ParseObjects,我想在同一时间保存InBackGround。
protected ParseObject aroundPost(){
ParseObject around = new ParseObject(ParseConstants.CLASS_AROUNDME);
around.put(ParseConstants.KEY_SENDER_NAME,ParseUser.getCurrentUser().getUsername());
around.put(ParseConstants.KEY_SENDER_ID, ParseUser.getCurrentUser().getObjectId());
ParseFile file = new ParseFile("peeps", fileBytes);
ParseFile thumbs = new ParseFile("thumbs",image);
around.put(ParseConstants.KEY_FILE, file);
around.put(ParseConstants.KEY_THUMB, thumbs);
if (fileBytes == null) {
return null;
} else {
return around;
}
}
protected ParseObject createMessage() {
ParseObject message = new ParseObject(ParseConstants.CLASS_MESSAGES);
message.put(ParseConstants.KEY_SENDER_ID, ParseUser.getCurrentUser().getObjectId());
message.put(ParseConstants.KEY_SENDER_NAME, ParseUser.getCurrentUser().getUsername());
message.put(ParseConstants.KEY_RECIPIENT_IDS, getRecipientIds());
if (fileBytes == null) {
return null;
}
else {
ParseFile file = new ParseFile("peeps", fileBytes);
ParseFile thumbs = new ParseFile("thumbs",image);
message.put(ParseConstants.KEY_FILE, file);
message.put(ParseConstants.KEY_THUMB, thumbs);
return message;
}
}
我创建了Send函数将数据上传到ParseCloud。
protected void send(ParseObject message) {
message.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
// success!
Toast.makeText(RecipientsActivity.this, R.string.success_message, Toast.LENGTH_LONG).show();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(RecipientsActivity.this);
builder.setMessage(R.string.error_sending_message)
.setTitle(R.string.error_selecting_file_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
这是我运行send函数的OnClickListener。这里我添加了Object createMessage但是如何添加aroundPost同时上传?
@Override
public void onClick(View view) {
// Click action
ParseObject message = createMessage();
if (message == null) {
// error
AlertDialog.Builder builder = new AlertDialog.Builder(RecipientsActivity.this);
builder.setMessage(R.string.error_selecting_file)
.setTitle(R.string.error_selecting_file_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
} else {
send(message);
finish();
}