Increase the memory allocated for the application

I am trying to display images taken by the camera and display them in an application. When I take images with a low resolution (say, 100 kB), I have no problems switching to a raster display, cons, when I take them with a high resolution (1.5 MB), the application crashes with the exception

Error java.lang.OutOfMemoryError. 

this happens on my smartphone (Samsung Galaxy SII, SIII Galaxy) on all shelves. At the moment, I decided manually, reducing the quality and size of the photos, but given the evolution of cameras with increasing resolution, this problem is likely to occur more often. Is there a permanent solution to increase the amount of memory allocated for my Android application without manually interfering with the device and the code?

Images are saved in bitmap format

  //image creation Uri domuri1 ContentValues cv = new ContentValues(); cv.remove("101"); domuri1 = getContentResolver().insert(Media.EXTERNAL_CONTENT _URI, cv); File domthumb1 = new File(domuri1.toString(), fileName1); //increment photo apparate Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); intent.putExtra(MediaStore.EXTRA_OUTPUT, domuri1); startActivityForResult(intent, 100); //images save ContentResolver cr = getContentResolver(); bitmap1 = MediaStore.Images.Media.getBitmap(cr, domuri1 ); imageView.setImageBitmap(bitmap1); 
+7
source share
1 answer

The default value for a regular application is 16 MB, and you can use android:largeHeap="true" (which can increase memory up to 64 MB) in your brightest file inside the applicattion tag. You can get the memory values ​​assigned to you by ActivityManager.getMemoryClass () and ActivityManager.getLargeMemoryClass () .

Even if you ask for largeHeap , the android will assign more memory, if you need it at all.

+13
source

All Articles