Android error setImageURI from memory

I have very little activity that should show an image.

If the image is not very small (for example, 1.12 Mb 2560x1920), it displays the orientation of the change screen from the memory. I tried getDrawable.setCallback (null) but no luck.

Where am I mistaken?

public class Fullscreen extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); System.gc(); setContentView(R.layout.fullscreen); ImageView imageView = (ImageView) findViewById(R.id.full_screen_image); long imageId = 2; imageView.setImageURI(Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + imageId)); } } 
+7
android memory image
source share
4 answers

Consume less memory and reduce size / size (see the documentation for BitmapOptions # inSampleSize).

+4
source share

Try adding this to your onDestroy method:

 ImageView imageView = (ImageView) findViewById(R.id.full_screen_image); BitmapDrawable bd = (BitmapDrawable)imageView.getDrawable(); bd.getBitmap().recycle(); imageView.setImageBitmap(null); 

It will recycle the bitmap used inside your ImageView.

+11
source share

Your application must have a context leak. This is usually the reason the application crashes after several orientation changes. Read this carefully http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html .

+1
source share

You can also use something like this:

  File picture = new File("path_to_image"); if (picture.exists()) { ImageView imageView = (ImageView)findViewById(R.id.imageView); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; Bitmap myBitmap = BitmapFactory.decodeFile(picture.getAbsolutePath(), options); imageView.setImageBitmap(myBitmap); } 

Read the following link for more information on BitmapFactory options (especially inSampleSize, which controls the degree of subsampling): http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html

+1
source share

All Articles