How to resolve out of memory exception when loading large images in Android?
When you try to load large size images in image editor in Android, you may get out of memory exception because this application cannot handle large size images. You can resolve this exception by using the following two ways:
Methods to resolve out of memory exception
1. Set largeHeap value as true in Android project.
2. Set largeHeap size for application.
How to set largeHeap value as true in Android project?
Code Snippet
To set largeHeap value as true in Android project, refer the following code snippet.
<manifest xmlns:android=http://schemas.android.com/apk/res/android android:installLocation="preferExternal"> <uses-sdk android:minSdkVersion="15" /> <application android:label="ImageEditor_GettingStarted.Android" android:largeHeap="true"></application> </manifest>
To set largeHeap value as true, refer the following steps:
Step 1: Expand properties tab in Android project.
Step 2: In AndroidManifest.xml file, set largeHeap value as true. Please refer the following screenshot for better understanding.
How to set largeHeap size in application?
To set largeHeap size in application, follow the below steps:
Step 1: Right-click the Android project, and then select Properties.
Step 2: In Android options, select Advance and set Java Max Heap size as 1G.