Theodor Paulus
Theodor Paulus

Reputation: 151

My ImageView doesn't refresh

I am trying to make an application that takes a picture and it display it on ImageView.

I succeded to make this but when I try to make a new picture the image from ImagaView is not refreshed.

For example: I push a button, an Intent to the Camera is created. I take picture 'A' which is saved on a file on the SD card at path 'fileUri'. Back in my activity mImageView1 shows the picture 'A'. Nice.It works.

I try to take a new picture 'B', I call the Intent the picture is saved at same adress.The picture is corectly saved, but when I return in my activity mImageView1 shows the old picture 'A'. Here is the code that changes the image of the ImageView:

@Override
public void onPause(){
    super.onPause();
    ((BitmapDrawable) mImageView1.getDrawable()).setCallback(null);
}

@Override
public void onResume(){
    super.onResume();
    try{
        if(bImageSaved)
        {
            mImageView1.setImageURI(fileUri);
            mImageView1.postInvalidate();

        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
         Log.e("Image2Notes",  e.getMessage(), e);
    }

I tried different things to refresh the ImageView: mImageView1.postInvalidate(); mImageView1.draw(...); without succes.

If you have a hint I will be greatefull. Thank you,

Upvotes: 0

Views: 523

Answers (1)

Vishal Vijay
Vishal Vijay

Reputation: 2528

Start your camera activity for result using startActivityForResilt(). And then override function onActivityResult (). So that when your camera activity finishes onActivityResult () function will get called. There in that function you can change the image other than changing it in onResume (). Check the activity result status in onActivityResult ().

Upvotes: 1

Related Questions