I have a few screens in my app. Each screen pulls data from a rest service. This task is called in OnAppearing event of each screen. The data is displayed as listview on each screen. List view has images, buttons etc. If I switch between these screens very quickly for sometime, then the app crashes with following exception-
Java.Lang.OutOfMemoryError: at at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () at at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m0 (object) at Android.App.SyncContext/cAnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18 at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36 at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.IRunnable.cs:71 at at (wrapper dynamic-method) object.54b3d2c7-28b2-41bb-86e3-3c830006c6be (intptr,intptr) at --- End of managed exception stack trace --- at java.lang.OutOfMemoryError at at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) at at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:709) at at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:685) at at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:723) at at dalvik.system.NativeStart.run(Native Method)
Is there a way that I can avoid this crash. I can put caching on images in listview?
I am enabling caching in the custom layout of the listview cell like this-
protected override void OnBindingContextChanged ()
{
base.OnBindingContextChanged ();
if (_image != null)
_image.Source = new UriImageSource () {
Uri=new Uri((this.BindingContext as ItemOrder).ImageUri),
CachingEnabled=true,
CacheValidity=new TimeSpan(1,0,0)
};
}
Any idea would be very helpful.
Thanks
Apurva