如果我在EditActivity中更改了新图像,则更改后的图像将被反映出来,但是在按下保存按钮之前,它将被带到应用程序的开始屏幕。当我查看logcat时,没有看到任何特殊错误,但是我想知道是什么原因造成的。
这是EditProfileActivity源
下班后的uploadImage方法很快就可以回家了...但是反映了更改的图像
private void updateProfile(String fullname, String username, String bio) {
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("fullname", fullname);
hashMap.put("username", username);
hashMap.put("bio", bio);
reference.updateChildren(hashMap);
}
private String getFileExtension(Uri uri){
ContentResolver contentResolver = getContentResolver();
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
return mimeTypeMap.getExtensionFromMimeType(contentResolver.getType(uri));
}
private void uploadImage(){
// Progress .xml에서 Visible 하는거 구현
final ProgressBar pd = new ProgressBar(this);
pd.setVisibility(View.VISIBLE);
//To show ProgressBar
if (mImageUri != null){
final StorageReference filereference = storageRef.child(System.currentTimeMillis()
+"."+getFileExtension(mImageUri));
uploadTask = filereference.putFile(mImageUri);
uploadTask.continueWithTask(new Continuation() {
@Override
public Object then(@NonNull Task task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}
return filereference.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()){
Uri downloadUri = task.getResult();
String myUrl = downloadUri.toString();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("imageurl", ""+myUrl);
reference.updateChildren(hashMap);
pd.setVisibility(View.INVISIBLE);
} else {
showMessage("Failed");
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
showMessage(e.getMessage());
}
});
}else {
showMessage("이미지를 선택해주세요");
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK){
CropImage.ActivityResult result = CropImage.getActivityResult(data);
mImageUri = result.getUri();
uploadImage();
}else {
showMessage("무엇인가 잘못되었습니다.");
}
}
private void showMessage(String text) {
Toast.makeText(getApplicationContext(),text,Toast.LENGTH_LONG).show();
}
这是我的HomeActivity
package com.example.together.Activities;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import com.example.together.Fragment.SearchFragment;
import com.example.together.Fragment.HomeFragment;
import com.example.together.Fragment.NotificationFragment;
import com.example.together.Fragment.ProfileFragment;
import com.example.together.R;
import com.google.firebase.auth.FirebaseAuth;
public class HomeActivity extends AppCompatActivity {
BottomNavigationView bottomNavigationView;
Fragment seletedFragment = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
bottomNavigationView = findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(navigationItemSelectedListener);
Bundle intent = getIntent().getExtras();
if (intent != null){
String publisher = intent.getString("publisherid");
SharedPreferences.Editor editor = getSharedPreferences("PREFS", MODE_PRIVATE).edit();
editor.putString("profileid", publisher);
editor.apply();
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, new ProfileFragment()).commit();
} else{
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, new HomeFragment()).commit();
}
}
private BottomNavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.nav_bottomBar_home:
seletedFragment = new HomeFragment();
break;
case R.id.nav_bottomBar_search:
seletedFragment = new SearchFragment();
break;
case R.id.nav_bottomBar_notification:
seletedFragment = new NotificationFragment();
break;
case R.id.nav_bottomBar_profile:
SharedPreferences.Editor editor = getSharedPreferences("PREFS", MODE_PRIVATE).edit();
editor.putString("profileid", FirebaseAuth.getInstance().getCurrentUser().getUid());
editor.apply();
seletedFragment = new ProfileFragment();
break;
}
if (seletedFragment != null){
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, seletedFragment).commit();
}
return true;
}
};
}
是什么让它改变了屏幕? 即使没有打算去HomeActivity ...