title: App Crashes on Some Devices | Memory Issue?
body: <p>So I recently finished initial development of my app. I'd been using my phone(OnePlus 2) the entire time for debugging and things were generally fine.
  I decided to take some help from friends and family for testing the app and some have reported that the app crashes on startup. So I got hold of my mom's phone (Galaxy S5) and decided to logcat the error on that.</p>
  
  <p>Logcat</p>
  
  <pre><code>04-16 10:23:02.400 3229-3229/? I/Timeline: Timeline: Activity_launch_request id:com.test.drawernav time:3576923
  04-16 10:23:02.730 3229-3229/? V/BitmapFactory: DecodeImagePath(decodeResourceStream3) : res/drawable-xxhdpi-v4/abc_ic_ab_back_mtrl_am_alpha.png
  04-16 10:23:02.835 3229-3229/? V/BitmapFactory: DecodeImagePath(decodeResourceStream3) : res/drawable/bg.jpg
  04-16 10:23:02.885 3229-3229/? I/art: Alloc sticky concurrent mark sweep GC freed 1308(219KB) AllocSpace objects, 5(80KB) LOS objects, 6% free, 118MB/126MB, paused 381us total 23.063ms
  04-16 10:23:02.895 3229-3229/? I/art: Clamp target GC heap from 134MB to 128MB
  04-16 10:23:02.895 3229-3229/? I/art: Alloc partial concurrent mark sweep GC freed 481(22KB) AllocSpace objects, 0(0B) LOS objects, 7% free, 118MB/128MB, paused 346us total 9.467ms
  04-16 10:23:02.915 3229-3229/? I/art: Clamp target GC heap from 134MB to 128MB
  04-16 10:23:02.915 3229-3229/? I/art: Alloc concurrent mark sweep GC freed 58(14KB) AllocSpace objects, 0(0B) LOS objects, 7% free, 118MB/128MB, paused 392us total 18.452ms
  04-16 10:23:02.915 3229-3229/? I/art: Forcing collection of SoftReferences for 43MB allocation
  04-16 10:23:02.935 3229-3229/? I/art: Clamp target GC heap from 134MB to 128MB
  04-16 10:23:02.935 3229-3229/? I/art: Alloc concurrent mark sweep GC freed 11(344B) AllocSpace objects, 0(0B) LOS objects, 7% free, 118MB/128MB, paused 521us total 17.392ms
  04-16 10:23:02.980 3229-3229/? E/art: Throwing OutOfMemoryError "Failed to allocate a 45619212 byte allocation with 9890668 free bytes and 9MB until OOM"
  04-16 10:23:02.980 3229-3229/? D/skia: --- allocation failed for scaled bitmap
  04-16 10:23:02.985 3229-3229/? D/AndroidRuntime: Shutting down VM
  04-16 10:23:03.010 3229-3229/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.test.drawernav, PID: 3229
                                                   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.drawernav/com.test.drawernav.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v4.widget.DrawerLayout
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)
                                                       at android.app.ActivityThread.access$900(ActivityThread.java:172)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                       at android.os.Looper.loop(Looper.java:145)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5832)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
                                                    Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v4.widget.DrawerLayout
                                                       at android.view.LayoutInflater.createView(LayoutInflater.java:640)
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
                                                       at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
                                                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
                                                       at com.test.drawernav.MainActivity.onCreate(MainActivity.java:32)
                                                       at android.app.Activity.performCreate(Activity.java:6221)
                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723) 
                                                       at android.app.ActivityThread.access$900(ActivityThread.java:172) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                       at android.os.Looper.loop(Looper.java:145) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5832) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at java.lang.reflect.Method.invoke(Method.java:372) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
                                                    Caused by: java.lang.reflect.InvocationTargetException
                                                       at java.lang.reflect.Constructor.newInstance(Native Method)
                                                       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
                                                       at android.view.LayoutInflater.createView(LayoutInflater.java:614)
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750) 
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:483) 
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:366) 
                                                       at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
                                                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
                                                       at com.test.drawernav.MainActivity.onCreate(MainActivity.java:32) 
                                                       at android.app.Activity.performCreate(Activity.java:6221) 
                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) 
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611) 
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723) 
                                                       at android.app.ActivityThread.access$900(ActivityThread.java:172) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                       at android.os.Looper.loop(Looper.java:145) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5832) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at java.lang.reflect.Method.invoke(Method.java:372) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
                                                    Caused by: java.lang.OutOfMemoryError: Failed to allocate a 45619212 byte allocation with 9890668 free bytes and 9MB until OOM
                                                       at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                       at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                                                       at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:741)
                                                       at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:562)
                                                       at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1014)
                                                       at android.content.res.Resources.loadDrawableForCookie(Resources.java:3723)
                                                       at android.content.res.Resources.loadDrawable(Resources.java:3596)
                                                       at android.content.res.TypedArray.getDrawable(TypedArray.java:750)
                                                       at android.view.View.&lt;init&gt;(View.java:3939)
                                                       at android.view.ViewGroup.&lt;init&gt;(ViewGroup.java:511)
                                                       at android.view.ViewGroup.&lt;init&gt;(ViewGroup.java:507)
                                                       at android.support.v4.widget.DrawerLayout.&lt;init&gt;(DrawerLayout.java:351)
                                                       at android.support.v4.widget.DrawerLayout.&lt;init&gt;(DrawerLayout.java:347)
                                                       at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                       at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
                                                       at android.view.LayoutInflater.createView(LayoutInflater.java:614) 
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750) 
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:483) 
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:366) 
                                                       at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
                                                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
                                                       at com.test.drawernav.MainActivity.onCreate(MainActivity.java:32) 
                                                       at android.app.Activity.performCreate(Activity.java:6221) 
                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) 
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611) 
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723) 
                                                       at android.app.ActivityThread.access$900(ActivityThread.java:172) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                       at android.os.Looper.loop(Looper.java:145) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5832) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at java.lang.reflect.Method.invoke(Method.java:372) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
  </code></pre>
  
  <p>The main activity is called after a Splash Screen (which runs on every phone) is displayed for 5 seconds. The main activity houses a navigation drawer around which the entire application has been designed.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBar;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  
  import java.util.ArrayList;
  
  public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
  
      private ActionBarDrawerToggle drawerToggle;
      private ActionBar actionBar;
      private DrawerLayout drawerLayout;
      private ListView navList;
      private FragmentTransaction fragmentTransaction;
      private FragmentManager fragmentManager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          navList = (ListView) findViewById(R.id.navigationdrawer);
          ArrayList&lt;String&gt; navArray = new ArrayList&lt;String&gt;();
          navArray.add("Home");
          navArray.add("About Us");
          navArray.add("Our Work");
          navArray.add("Locate Us");
          navArray.add("Contact Us");
  
  
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
                  android.R.layout.simple_list_item_activated_1,
                  navArray);
          navList.setAdapter(adapter);
          navList.setOnItemClickListener(this);
          navList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
  
  
          drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
          drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.open_drawer, R.string.close_drawer);
  
          drawerLayout.setDrawerListener(drawerToggle);
  
          actionBar = getSupportActionBar();
          assert getSupportActionBar() != null;
          actionBar.setDisplayHomeAsUpEnabled(true);
          actionBar.setDisplayShowHomeEnabled(true);
          fragmentManager = getSupportFragmentManager();
          fragmentTransaction = fragmentManager.beginTransaction();
          loadSelection(0);
      }
  
      private void loadSelection(int i){
          navList.setItemChecked(i, true);
  
          switch (i){
              case 0:
                  HomeFragment homeFragment = new HomeFragment();
                  fragmentTransaction = fragmentManager.beginTransaction();
                  fragmentTransaction.replace(R.id.fragmentholder, homeFragment)
                          .commit();
                  break;
  
              case 1:
                  AboutUsFragment aboutUsFragment = new AboutUsFragment();
                  fragmentTransaction = fragmentManager.beginTransaction();
                  fragmentTransaction.replace(R.id.fragmentholder, aboutUsFragment)
                          .commit();
                  break;
  
              case 2:
                  HelplineFragment ourWorkFragment = new OurWorkFragment();
                  fragmentTransaction = fragmentManager.beginTransaction();
                  fragmentTransaction.replace(R.id.fragmentholder, ourWorkFragment)
                          .commit();
                  break;
  
              case 3:
                  LocateFragment locateFragment = new LocateFragment();
                  fragmentTransaction = fragmentManager.beginTransaction();
                  fragmentTransaction.replace(R.id.fragmentholder, locateFragment)
                          .commit();
                  break;
  
              case 4:
                  LocateFragment contactFragment = new ContactUsFragment();
                  fragmentTransaction = fragmentManager.beginTransaction();
                  fragmentTransaction.replace(R.id.fragmentholder, contactFragment)
                          .commit();
                  break;
  
  
          }
  
      }
  
      @Override
      protected void onPostCreate(Bundle savedInstanceState) {
          super.onPostCreate(savedInstanceState);
          drawerToggle.syncState();
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          int id = item.getItemId();
  
          if (id == android.R.id.home) {
              if (drawerLayout.isDrawerOpen(navList)) {
                  drawerLayout.closeDrawer(navList);
              } else {
                  drawerLayout.openDrawer(navList);
              }
  
          }
             return super.onOptionsItemSelected(item);
          }
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
          loadSelection(position);
          drawerLayout.closeDrawer(navList);
      }
  
  
  
  }
  </code></pre>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v4.widget.DrawerLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/drawerLayout"
      android:background="@drawable/bg"
      &gt;
  
      &lt;FrameLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/fragmentholder"&gt;    &lt;/FrameLayout&gt;
  
      &lt;ListView
          android:layout_width="240dp"
          android:layout_height="match_parent"
          android:id="@+id/navigationdrawer"
          android:layout_gravity="start"
          android:background="#ccddccdd"
          &gt;&lt;/ListView&gt;
  
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>HomeFragment.java</p>
  
  <pre><code>import android.content.Context;
  import android.content.DialogInterface;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  import android.widget.ViewFlipper;
  
  
  public class HomeFragment extends Fragment {
  
   //   ViewFlipper topFlipper;
      ViewFlipper bottomFlipper;
  
  
      public HomeFragment() {
          // Required empty public constructor
      }
  
      @Override
      public void onAttach(Context context) {
          super.onAttach(context);
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState)
      {
          View view = inflater.inflate(R.layout.fragment_home, container, false);
  
  
          TextView textView = (TextView)view.findViewById(R.id.home_fragment_text);
  
          bottomFlipper = (ViewFlipper)view.findViewById(R.id.bottomFlipper);
          bottomFlipper.setAutoStart(true);
          bottomFlipper.setFlipInterval(2000);
          bottomFlipper.startFlipping();
  
      return view;
      }
  
  
  
      @Override
      public void onDestroy() {
          super.onDestroy();
      }
  
      @Override
      public void onDetach() {
          super.onDetach();
      }
  }
  </code></pre>
  
  <p>fragment_home.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.test.drawernav.HomeFragment"&gt;
  
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"&gt;
  
          &lt;TextView
              android:layout_marginTop="10dp"
              android:layout_marginLeft="5dp"
              android:layout_marginRight="5dp"
              android:layout_marginBottom="10dp"
              android:gravity="center"
              android:layout_width="match_parent"
              android:layout_height="0dp"
              android:layout_weight="1"
              android:id="@+id/home_fragment_text"
              android:text="@string/home_fragment_text"
              android:textSize="27sp"
               /&gt;
  
          &lt;ViewFlipper
              android:layout_width="match_parent"
              android:layout_height="0dp"
              android:layout_gravity="bottom"
              android:layout_weight="2"
              android:id="@+id/bottomFlipper"&gt;
  
              &lt;ImageView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@+id/bottomFlipper1"
                  android:src="@drawable/flipper1"/&gt;
  
              &lt;ImageView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@+id/bottomFlipper2"
                  android:src="@drawable/flipper2"/&gt;
  
              &lt;ImageView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@+id/bottomFlipper3"
                  android:src="@drawable/flipper3"/&gt;
  
              &lt;ImageView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@+id/bottomFlipper4"
                  android:src="@drawable/flipper4"/&gt;
  
              &lt;ImageView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@+id/bottomFlipper5"
                  android:src="@drawable/flipper5"/&gt;
  
              &lt;ImageView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@+id/bottomFlipper6"
                  android:src="@drawable/flipper6"/&gt;
  
  
          &lt;/ViewFlipper&gt;
  
  
  &lt;/LinearLayout&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>Its got something to do with memory allocation is what I gather, but I have no idea how to fix it.</p>