Android - how to carry information from imageView from one class to another?

0

Hello, I need to transport the contents of an ImageView from one class to another, I tried Intent, but I could not get it. I have a Drawable that was edited in ImageView from the first class and I want to move this already edited content to another ImageView from another class.

I tried this way as shown below but did not work ..

In first class:

public void next(View v){
    //resultView é uma ImageView
    Bitmap p = drawableToBitmap(resultView.getDrawable());

    Bundle param = new Bundle();
    param.putParcelable("BITMAP", p);

    Intent intent = new Intent(this, EditImage.class);
    intent.putExtras(param);
    startActivity(intent);
}

In second class:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState == null) {
        setContentView(R.layout.activity_main);

        Intent intent = getIntent();
        Bundle param = intent.getExtras();
        Bitmap  bit = param.getParcelable("BITMAP");
        resultView.setImageBitmap(bit);
...
}

From now on I thank you for the help and attention, in case anyone has any ideas or tips on how to do it please inform, all help is valid. Hugs!

    
asked by anonymous 10.12.2015 / 18:05

1 answer

1

Well, I've been trying here and I've got it this way:)

In Class 1:

public void next(View v){
    Bitmap p = drawableToBitmap(resultView.getDrawable());

    Bundle param = new Bundle();
    param.putParcelable("BITMAP", p);

    Intent intent = new Intent(this, Classe2.class);
    intent.putExtras(param);
    startActivity(intent);
}

In Class 2:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

        Intent intent = getIntent();
        Bundle param = intent.getExtras();
        Bitmap  bit = param.getParcelable("BITMAP");
        Drawable drawable=new BitmapDrawable(bit);
        resultView.setImageDrawable(drawable);
        ...
}

Thanks for the help and attention! :)

    
10.12.2015 / 20:03