当前位置: 首页 > 知识库问答 >
问题:

在Android中,我如何将图像从一个活动传递到另一个活动?

齐成双
2023-03-14
public void salvarDados(){
    String usrname = edtEmailSettings.getText().toString();
    String name = edtNameField.getText().toString();
    String phone = edtPhoneField.getText().toString();
    String company = edtCompanySettings.getText().toString();
    String photo = imgProfileImage.toString();
    if(!savelogincheckbox.isChecked()){
        editor.putBoolean("savelogin",true);
        editor.putString("user",usrname);
        editor.putString("nam", name);
        editor.putString("phon", phone);
        editor.putString("company", company);
        editor.putString("image", photo);
        editor.commit();
    }
}
saveLogin = sharedPreferences.getBoolean("saveLogin", true);
    if (saveLogin == true){
        edtEmail.setText(sharedPreferences.getString("user", null));
        edtNome.setText(sharedPreferences.getString("nam", null));
        imgProfileImage.set // I do not know what to do here
    }

共有1个答案

孙玮
2023-03-14

位图实现了可打包接口,所以...

您可以使用Parcelable通过intent.putExtra()传递位图:

Intent intent = new Intent(this, MyActivity.class);
intent.putExtra("MY_BITMAP", mBitmap);
startActivity(intent);

在new Activity中,阅读这篇额外的文章,并将onCreate方法放在您想要的地方:

Bitmap destinationBitmap = (Bitmap) getIntent().getParcelableExtra ("MY_BITMAP");
 类似资料: