Reputation: 851
am getting out of memory exception while loading image
String filePath = Environment.getExternalStorageDirectory()
.getAbsolutePath() + File.separator + "/Omoto Images/background image.jpg";
Bitmap bmp = BitmapFactory.decodeFile(filePath);
page4image.setImageBitmap(bmp);
above code is for loading image from internal storage
Upvotes: 0
Views: 3742
Reputation: 1014
You can increase the heap memory of the application by using the largeheap="true" in AndroidManifest.
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true">
</application>
But, it is not good practice to use it unless it is needed.
Official doc states
Whether your application's processes should be created with a large Dalvik heap. This applies to all processes created for the application. It only applies to the first application loaded into a process; if you're using a shared user ID to allow multiple applications to use a process, they all must use this option consistently or they will have unpredictable results. Most apps should not need this and should instead focus on reducing their overall memory usage for improved performance. Enabling this also does not guarantee a fixed increase in available memory, because some devices are constrained by their total available memory.
Upvotes: 1
Reputation: 616
You shouldn't handle the OutOfMemory exception. The good explanation is described here: Catching java.lang.OutOfMemoryError?
Upvotes: 0