ImageView is crashing my app

zzinzzin CAMember ✭✭

ndroidRuntime] Caused by: java.lang.reflect.InvocationTargetException
[AndroidRuntime] at java.lang.reflect.Constructor.constructNative(Native Method)
[AndroidRuntime] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[AndroidRuntime] at android.view.LayoutInflater.createView(LayoutInflater.java:594)
[AndroidRuntime] ... 25 more
[AndroidRuntime] Caused by: java.lang.OutOfMemoryError
[AndroidRuntime] at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
[AndroidRuntime] at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
[AndroidRuntime] at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
[AndroidRuntime] at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
[AndroidRuntime] at android.content.res.Resources.loadDrawable(Resources.java:2113)
[AndroidRuntime] at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
[AndroidRuntime] at android.widget.ImageView.(ImageView.java:139)
[AndroidRuntime] at android.widget.ImageView.(ImageView.java:129)
[AndroidRuntime] ... 28 more

Answers

  • zzinzzin CAMember ✭✭

    need help.

  • StevaSteva RSMember ✭✭✭

    For some strange reason when activity was destroyed drawable set from resources wasn't cleared from memory and was giving me same troubles. This was just a wild guess from my side but setting image drawable to null prior to activity being destroyed fixed the memory issues for me.

    public override void OnDestroy()
    {
        base.OnDestroy();
        _ivThatIsCausingMemoryLeak.SetImageDrawable(null);      
    }
    
  • zzinzzin CAMember ✭✭

    i have a question @Steva , do i need to use Ondestroy, Onresume, OnStart() etc because currently all i use is OnCreate()

  • StevaSteva RSMember ✭✭✭

    Well in this case you need OnDestroy but generaly you only use what you need. If in your case you only need OnCreate then just use that one.

  • zzinzzin CAMember ✭✭

    also, the ondestroy() did not help sadly

Sign In or Register to comment.