Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

increase the memory allocated to application

I try to display images taken by the camera and display them in the application. When I take low-resolution images (say 100kB in size), I have no problems with the switch to bitmapped display, cons when I take them in high resolution (1.5MB), the application crashes with the exception

  Error java.lang.OutOfMemoryError. 

it happens to be on my smartphone (Samsung Galaxy SII, SIII Galaxy) is on all the shelves. For now I solved manually by lowering the quality and size of the photos but, given the evolution of cameras with increasing resolution, this problem is likely to arise more often. Is there not a permanent solution to increase the memory allocated to my application for Android without manual intervention on the device and in the code?

Images are stored 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);
like image 715
vetic Avatar asked Jul 19 '12 09:07

vetic


People also ask

How do I increase allocated memory?

Increasing Virtual Memory in Windows 10Go to the Start Menu and click on Settings. Type performance. Choose Adjust the appearance and performance of Windows. In the new window, go to the Advanced tab and under the Virtual memory section, click on Change.

How do I increase allocated memory on my PC?

Open the "Task Manager" in Windows and click the Processes option and right click the desired priority process. Click Set Priority and the RAM will now focus on that specific program. It will speed up and operate more efficiently with the newly allocated RAM.

Can we allot more memory to a specific application?

Prioritize RAM Usage Open Task Manager and right-click the application you want to prioritize, then select Go to details. This opens the Details tab of the Task Manager. Right-click the process and choose Set priority.


1 Answers

The default memory value for a normal App is 16MB and You can use android:largeHeap="true" (which may increase memory up to 64MB) in your manifiest 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 only assign more memory if at all your application needs it.

like image 51
Amit Avatar answered Oct 30 '22 13:10

Amit