0

Using this library, I'm trying to retrieve the edited image and place it on another activity's ImageView...

Calling the function to set the edited drawable to the other ImageView:

Log.d("eiDR",gImageView.getDrawable().toString());
PreviewPostal pp = new PreviewPostal();
pp.setImage(gImageView.getDrawable());

Setting the edited drawable to the other ImageView (in PreviewPostal Activity):

public void setImage(Drawable dr){
    Log.d("ppDR",dr.toString());
    //ImageView iv = (ImageView)this.findViewById(R.id.imageForTest);
    //iv.setImageDrawable(dr);
}

This logs the same drawable, but if I uncomment those two lines, it gives me a NPE.

Note: The activities are wrapped in a TabHost (each activity are a tab with their own layouts).

Thanks in advance!

Edit: How I add the activities (tabs):

mTabHost = getTabHost();

// Tab Editar Imagem
TabSpec editImageSpec = mTabHost.newTabSpec("Imagem");
editImageSpec.setIndicator(setTabIndicator(getResources().getDrawable(R.drawable.tab_editimage_icon)));
Intent editImageIntent = new Intent(this, EditImage.class);
editImageIntent.putExtra("imagem", getIntent().getStringExtra("imagem"));
editImageSpec.setContent(editImageIntent);
silentw
  • 4,835
  • 4
  • 25
  • 45
  • Are you sure that you are using the same layout(which contains imageForTest) with setContentView in PreviewPostal Activity? – Imran Rana Jun 08 '12 at 11:30
  • Yes, but the problem might be that when I try to do this: `iv.setImageDrawable(dr);` the ImageView isn't initialized... – silentw Jun 08 '12 at 11:31

2 Answers2

1

You cannot do this simply. First let me explain you the meaning of this line.

ImageView iv = (ImageView)this.findViewById(R.id.imageForTest);

This simply means, you are trying to refer to a element which is present in your current Activity. That is, the layout which you could have provided by using setContentView. So now when android searches for this ImageView in the current layout , obviously it will not exist and throw you a Null Pointer Exception.

What you actually have to do is, save the Drawable by some means and later when you pass to that activity, you have to set the Drawable to that ImaegView.

Refer this link, on how to convert your Drawable to Bitmap and send it to next activity using putExtra.

https://stackoverflow.com/a/9033864/603744

Community
  • 1
  • 1
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
1

Options:

1.You can start activity for result and on result of the called activity just return the byte[] of the drawable back to the calling activity

2.Have a pre-defined location on SD card,then save the image from called activity at that location and access the same location from calling activity

3.Write a simple pojo which implements serializable.Then start second activity for result and on result of second activity populate the pojo and return it from called activity to calling activity.

I hope this helps..

ranjeet wagh
  • 306
  • 3
  • 2
  • I think that `startActivityForResult` isn't the best option for me, maybe saving the image to the SDCard and then fetch it... Maybe it's better that way... Thanks for the tips! – silentw Jun 08 '12 at 15:49