i m using this code : Initially when i select image from gallery the same image is shown to user sometimes twice , thrice or even 5times . After some interval of time its showing fine why is this happening ?
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK)
{
Uri selectedImageUri = data.getData();
Log.d(TAG,"path:"+selectedImageUri.toString());
StorageReference photoReference = mStorageReference.child("images/"+selectedImageUri.getLastPathSegment());
photoReference.putFile(selectedImageUri).addOnSuccessListener(this, new OnSuccessListener() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUri = taskSnapshot.getDownloadUrl();
MessageModelClass messageModelClass = new MessageModelClass();
messageModelClass.setImageUrl(downloadUri.toString());
messageModelClass.setmMessage(null);
messageModelClass.setmUserName(userName);
mDatabaseReference.push().setValue(messageModelClass);
//messageAdapter.notifyDataSetChanged();
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
}).addOnCompleteListener(this, new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
messageAdapter.notifyDataSetChanged();
}
});
}
but the last selected image from gallery is shown to the user sometimes twice or thrice ? Why is this happening ?
i m using this code : Initially when i select image from gallery the same image is shown to user sometimes twice , thrice or even 5times . After some interval of time its showing fine why is this happening ?
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK) { Uri selectedImageUri = data.getData(); Log.d(TAG,"path:"+selectedImageUri.toString()); StorageReference photoReference = mStorageReference.child("images/"+selectedImageUri.getLastPathSegment()); photoReference.putFile(selectedImageUri).addOnSuccessListener(this, new OnSuccessListener() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUri = taskSnapshot.getDownloadUrl();
MessageModelClass messageModelClass = new MessageModelClass();
messageModelClass.setImageUrl(downloadUri.toString());
messageModelClass.setmMessage(null);
messageModelClass.setmUserName(userName);
mDatabaseReference.push().setValue(messageModelClass);
//messageAdapter.notifyDataSetChanged();
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
but the last selected image from gallery is shown to the user sometimes twice or thrice ? Why is this happening ?