title: Getting out of memory error while starting a Activity in android App?
body: <p>I am working on an app where one activity is a very complex code with <strong>different views inflated in a single layout like webview</strong>(which is using html files from sdcard with images),imageviews,scrolls.At starting this Activity I am getting these errors.</p>
  
  <pre><code>        E/AndroidRuntime(600): Caused by: java.lang.reflect.InvocationTargetException
          E/AndroidRuntime(600):  at java.lang.reflect.Constructor.constructNative(Native Method)
          E/AndroidRuntime(600):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
          E/AndroidRuntime(600):  at android.view.LayoutInflater.createView(LayoutInflater.java:586)
          E/AndroidRuntime(600):  ... 29 more
          E/AndroidRuntime(600): Caused by: java.lang.OutOfMemoryError
          E/AndroidRuntime(600):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
          E/AndroidRuntime(600):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
          E/AndroidRuntime(600):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
          E/AndroidRuntime(600):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
          E/AndroidRuntime(600):  at android.content.res.Resources.loadDrawable(Resources.java:1935)
          E/AndroidRuntime(600):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
          E/AndroidRuntime(600):  at android.view.View.&lt;init&gt;(View.java:2785)
          E/AndroidRuntime(600):  at android.view.View.&lt;init&gt;(View.java:2722)
          E/AndroidRuntime(600):  at android.view.ViewGroup.&lt;init&gt;(ViewGroup.java:379)
          E/AndroidRuntime(600):  at android.widget.RelativeLayout.&lt;init&gt;(RelativeLayout.java:174)
          E/AndroidRuntime(600):  ... 32 more
  </code></pre>
  
  <p>How to solve this problem I have tried this code but still not knowing what to do?</p>
  
  <pre><code> @Override
      protected void onDestroy() {
      super.onDestroy();
  
      unbindDrawables(findViewById(R.id.rootView));
      System.gc();
      }
  
      private void unbindDrawables(View view) {
          if (view.getBackground() != null) {
          view.getBackground().setCallback(null);
          }
          if (view instanceof ViewGroup) {
              for (int i = 0; i &lt; ((ViewGroup) view).getChildCount(); i++) {
              unbindDrawables(((ViewGroup) view).getChildAt(i));
              }
          ((ViewGroup) view).removeAllViews();
          }
      }
  </code></pre>
  
  <p>What is the possible way to solve this problem? Please Help</p>