I have an imageView with a set image in xml. However when I try to change the image the ImageView never displays the second image. Instead it displays a blank screen. I have tried the code with and without invalidate() and there is no change.
ImageView image; String imgPath=Environment.getExternalStorageDirectory()+"/Music/Evanescence - Discography - 1998-2011 (320 kbps)/Album's/2000 Origin (Limited Edition) (320 kbps)/Scans covers/06.jpg"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); image=(ImageView)findViewById(R.id.imageView1); image.setImageBitmap(BitmapFactory.decodeFile(imgPath)); if(!new File(imgPath).exists()) Log.i("aaa","File doesnt exist"); //select image from gallery //Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); //photoPickerIntent.setType("image/*"); //startActivityForResult(photoPickerIntent, SELECT_PHOTO); Log.i("aaa","DONE. img path: "+imgPath); }
invalidate()there becausesetImageBitmap()will redraw anyway. Are you doing anything with it inonResume()?BitmapFactory.decodeFile(imgPath)twice to null-check it. If it returns null on the second call for some reason, you won't get that "bitmap was null" message anyway.