@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_PICTURE) {
if (resultCode == RESULT_OK) {
Bitmap bitmap = null;
if (data != null) {
try {
bitmap = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}
userPicImageView.setImageBitmap(bitmap);
dialog = new ProgressDialog(this);
dialog.setTitle("Updating profile picture");
dialog.setMessage("Please, wait");
dialog.show();
final BackendlessUser user = Backendless.UserService.CurrentUser();
Backendless.Files.Android.upload(bitmap, Bitmap.CompressFormat.JPEG, 100, "profile_pic_" + user.getObjectId() + System.currentTimeMillis(), "images", new AsyncCallback<BackendlessFile>() {
@Override
public void handleResponse(final BackendlessFile response) {
Log.d(TAG, "updated profile pic");
Log.d(TAG,"FILE URL IS "+response.getFileURL().toString());
backendlessFile = response;
if (dialog.isShowing()) {
dialog.dismiss();
}
String currentUserID = Backendless.UserService.loggedInUser();
Backendless.UserService.findById(currentUserID, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser usr) {
Log.d(TAG,"CURRENT USER is "+usr.getProperty("name").toString());
usr.setProperty("image", response.getFileURL().toString());
Backendless.UserService.update(usr);
}
@Override
public void handleFault(BackendlessFault fault) {
[**problem here**-->] Log.e(TAG,"COULD NOT LOAD user");
}
});
}
@Override
public void handleFault(BackendlessFault fault) {
Log.e(TAG, "error " + fault.getMessage());
}
});
}
}
}
}
The above code handles the case when a user updates her profile with a picture from gallery. She uploads the file all right to Backendless file storage. The Users table has a column "image" that stores a link to the profile picture. I try to retrieve the current user and update her row by setting the image field to contain the link to the uploaded file, but the logs say they cannot access the user (the error location is marked problem here in the above code). Does this all have to do with Async requests? How can this be fixed?
[EDIT] I figured out that it all has to do with Async calls indeed. The thing is, Backenledss AsyncCallback seems not to have onPostExecute() method.