-2

I am creating a app which capture images and stores into Internal storage as well as local storage in ActiveAndroid. In starting i have faced many issues regarding OutofMemory error. But I have cured that error by handling and compressing image after go through here. But now when I am getting list from ActiveAndroid app crashes in some device and gives outofMemory error. Below is my code and error Response.

In Background Service I am getting List like:

 List<ImageUploadModel> imagesList = ImageUploadModel.getUnUploadedImageListonintimation(uploadImageModel.getIntimationId());

In active android my Query is

public static List<ImageUploadModel> getUnUploadedImageListonintimation(String IntimationId) {
    return new Select().from(ImageUploadModel.class).where("intimationId=?", IntimationId).where("isImageDetailsUpload=?", false).execute();
}

I am getting error

Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 422472 byte allocation with 343696 free bytes and 335KB until OOM
   at android.database.CursorWindow.nativeGetString(CursorWindow.java)
   at android.database.CursorWindow.getString(CursorWindow.java:438)
   at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:66)
   at com.activeandroid.Model.loadFromCursor(Unknown Source)
   at com.activeandroid.util.SQLiteUtils.processCursor(Unknown Source)
   at com.activeandroid.util.SQLiteUtils.rawQuery(Unknown Source)
   at com.activeandroid.query.From.execute(Unknown Source)
   at com.xxxxxxxxx.xxxxxxxxxxx.Model.ImageUploadModel.getUnUploadedImageListonintimation(Unknown Source)
   at com.xxxxxxxxx.xxxxxxxxxxx.Service.UploadImageService$3.getResponce(Unknown Source)
   at com.xxxxxxxxx.xxxxxxxxxxx.Volley.VollyRequests$1.onResponse(Unknown Source)
   at com.xxxxxxxxx.xxxxxxxxxxx.Volley.VollyRequests$1.onResponse(Unknown Source)
   at com.android.volley.toolbox.StringRequest.deliverResponse(Unknown Source)
   at com.android.volley.toolbox.StringRequest.onFinish(Unknown Source)
   at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(Unknown Source)
   at android.os.Handler.handleCallback(Handler.java:836)
   at android.os.Handler.dispatchMessage(Handler.java:103)
   at android.os.Looper.loop(Looper.java:203)
   at android.app.ActivityThread.main(ActivityThread.java:6343)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)
Shashwat Gupta
  • 876
  • 9
  • 22

1 Answers1

0

You need to handle your memory management more efficently.

My advice would be:

  • Take a look at this file to get an understanding of how memory is limited across different Android versions / screen sizes (note: it only shows it until Marshmallow)
  • Don't load your full sized image, load just a thumbnail of it.
  • Use the local storage of the phone instead of the database (won't really help with memory management but its more convenient :3)
  • Let Glide help you :)
  • In the list where you display the images, only load the ones that are currently needed (and only the thumbnails)
Rene Ferrari
  • 4,096
  • 3
  • 22
  • 28