How to handle FATAL EXCEPTION IN SYSTEM PROCESS: ActivityManager and java.lang.OutOfMemoryError: [memory exhausted]

I have a device (samsung fit galaxy). When I turn on the device, I can’t go to the Homescreen, and it just keeps loading. When I connect the device and see the log code, my logcat error showed -

"FATAL EXCEPTION IN SYSTEM PROCESS: ActivityManager and java.lang.OutOfMemoryError: [memory exhausted]" 

How to do it?

0
android
source share
2 answers

is there any way to solve the memory error problem

first disposal of a bitmap like this

 bmp.recycle(); bmp = null; 

second using the garbage collector

 System.runFinalization(); Runtime.getRuntime().gc(); System.gc(); 

but it would be better if you post some of your code here so that I and other people can help you :)

+1
source share

using the following code, you should check OutOfMemory Error

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) try { // We need to recyle unused bitmaps if (Main_bitmap != null) { Main_bitmap.recycle(); } Uri selectedImage = data.getData(); String[] filePathColumn = {MediaStore.Images.Media.DATA}; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); if (cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndex(filePathColumn[0]); filePath = cursor.getString(columnIndex); BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options(); bmpFactoryOptions.inJustDecodeBounds=true; BitmapFactory.decodeFile(filePath,bmpFactoryOptions); if ( checkBitmapFitsInMemory(bmpFactoryOptions.outWidth,bmpFactoryOptions.outHeight, 2)) { BitmapFactory.Options options4 = new BitmapFactory.Options(); options4.inSampleSize = 1; Main_bitmap = BitmapFactory.decodeFile(filePath, options4); iv_set_image.setImageBitmap(Main_bitmap); } else { Toast.makeText(this,"java.lang.OutOfMemoryError:", 1).show(); } cursor.close(); } catch (Exception e) { e.printStackTrace(); } super.onActivityResult(requestCode, resultCode, data); } public static boolean checkBitmapFitsInMemory(long bmpwidth,long bmpheight, int bmpdensity ) { long reqsize=bmpwidth*bmpheight*bmpdensity; long allocNativeHeap = Debug.getNativeHeapAllocatedSize(); final long heapPad=(long) Math.max(4*1024*1024,Runtime.getRuntime().maxMemory()*0.1); if ((reqsize + allocNativeHeap + heapPad) >= Runtime.getRuntime().maxMemory()) { return false; } return true; } 
0
source share

All Articles