I am working on Android Weather application where my requirement is to show animated forecast. We have a server from where I load forecast images as Bitmap using Glide and then create GoogleMap's GroundOveryayOption using the bitmap. I am using Runnable and Handler for animation.
Everything is working fine except the memory consumption and eventually I got "Out of memory exception"
In-order to smoothly run my forecast animation I have to load all the Bitmaps using Glide and create GroundOverlayOptions obj from Bitmap and store GroundOverlayOptions in HashMap as below.
@Override
public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap> transition) {
mBitmapLoaded = true;
//the actual image is png and its size is in KBs but Bitmap size is in MBs
Log.i("Weather", ""+ bitmap.getByteCount());
GroundOverlayOptions overlayOptions = new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromBitmap(bitmap))
.positionFromBounds(getLatLngBounds(mBounds))
.visible(frameVisible);
//groundOverlaysItemMap is a Hashmap to store GroundOverlayOptions where key is Time
groundOverlaysItemMap.put(mTime, mMap.addGroundOverlay(overlayOptions));
}
Any help is appreciated.