Move an image of an Activity to the main screen

Asked

Viewed 211 times

0

How can I pass an image of an Activity to another actiivity?

I have an image on my settings screen, I want to send it to my main screen.

I saved it in my sharedPreferences and would like to use the key on my other screen, just like I do with texts.

Activity where I am saving the data (editor.putString("image", photo);)

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();
    }
}

Now I don’t know how I’ll get the key ("image") in the other Activity, I can pick up texts and send a setText().

How to do this with image?

1 answer

2

I recommend that you pass your image through Intent, However, before you should convert the image to Bitmap and only then pass it via extra Intent

To move your image from the first Activity to the one you want, you need to do it this way:

In your Settings Activity:

imageView.buildDrawingCache();
Bitmap bitmap = imageView.getDrawingCache();

Intent intent = new Intent(this, ActivityAlvo.class);
intent.putExtra("BitmapImage", bitmap);

Recovering in Target Activity:

Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");

Note: the correct thing would be to save this image somewhere else and recover by going through it.

I hope it helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.