title: App stopped working Android Studio
body: <p>How many activities can I put in my project how many pictures? I make one project and have now 13 activities also and when I have between 5 and 8 activities, my project works wonderfully. Nothing stacks, nothing crashes and now I have 13 activities and when I build my project and open it, the welcome screen works and I can open one, two or three other activities but on 4 or 5 activities open and my app stops working and crashes. I think it is out of memory, but I don't understand why it happens because I have all of my bitmaps resized and compressed and when I start a new activity after <code>startActivity()</code> I put <code>finish()</code>.</p>
  
  <p>Here is one java code from nocnizivotActivity.java</p>
  
  <pre><code>package teslicinfo.teslic;
  
  import android.content.Intent;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  
  public class nocnizivotActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_nocnizivot);
  
  //tnt
  LinearLayout lyt_tnt =(LinearLayout)findViewById(R.id.lyt_tnt);
  lyt_tnt.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
          i.putExtra("data", "tnt");
          startActivity(i);
          finish();
      }
  });
  
  //moja kafanica
  LinearLayout lyt_mojakafanica =(LinearLayout)findViewById(R.id.lyt_mojakafanica);
  lyt_mojakafanica.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
          i.putExtra("data", "mojakafanica");
          startActivity(i);
          finish();
      }
  });
  
  //kaktus
  LinearLayout lyt_kaktus =(LinearLayout)findViewById(R.id.lyt_kaktus);
  lyt_kaktus.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
          i.putExtra("data", "kaktus");
          startActivity(i);
          finish();
      }
  });
  
  //caffex
  LinearLayout lyt_caffex =(LinearLayout)findViewById(R.id.lyt_caffex);
  lyt_caffex.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
          i.putExtra("data", "caffex");
          startActivity(i);
          finish();
      }
  });
  
  //faraon
  LinearLayout lyt_faraon =(LinearLayout)findViewById(R.id.lyt_faraon);
  lyt_faraon.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
          i.putExtra("data", "faraon");
          startActivity(i);
          finish();
      }
  });
  
  //lane
  LinearLayout lyt_trg =(LinearLayout)findViewById(R.id.lyt_trg);
  lyt_trg.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
          i.putExtra("data", "trg");
          startActivity(i);
          finish();
      }
  });
  
  //lane
  LinearLayout lyt_lane =(LinearLayout)findViewById(R.id.lyt_lane);
  lyt_lane.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
          i.putExtra("data", "lane");
          startActivity(i);
          finish();
      }
  });
  
  //kastel
  LinearLayout lyt_kastel =(LinearLayout)findViewById(R.id.lyt_kastel);
  lyt_kastel.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
          i.putExtra("data", "kastel");
          startActivity(i);
          finish();
      }
  });
  
  //cepelin
  LinearLayout lyt_cepelin =(LinearLayout)findViewById(R.id.lyt_cepelin);
  lyt_cepelin.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
          i.putExtra("data", "cepelin");
          startActivity(i);
          finish();
      }
  });
  
  
  LinearLayout lyt_dzungla =(LinearLayout)findViewById(R.id.lyt_dzungla);
  lyt_dzungla.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          Intent i = new Intent(getApplicationContext(), diskotekeActivity.class);
          i.putExtra("data","dzungla");
          startActivity(i);
          finish();
      }
  });
  
  
  ImageView imgnazad_nocnizivot =(ImageView)findViewById(R.id.imgnazad_nocnizivot);
  imgnazad_nocnizivot.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          Intent i = new Intent(getApplicationContext(), pocetakActivity.class);
          startActivity(i);
          finish();
      }
  });
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.menu_nocnizivot, menu);
  return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
  
  int id = item.getItemId();
  
  //noinspection SimplifiableIfStatement
  if (id == R.id.action_settings) {
      return true;
  }
  
  return super.onOptionsItemSelected(item);
  }
  }
  </code></pre>
  
  <p>and <a href="http://pastie.org/10548177" rel="nofollow noreferrer">here</a> is the nocnizivot_layout.xml code</p>
  
  <p>And this is my logcat:</p>
  
  <pre><code>11-10 10:49:40.169    2704-2704/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
  11-10 10:49:40.169    2704-2704/? I/art﹕ Late-enabling JIT
  11-10 10:49:40.169    2704-2704/? I/art﹕ JIT created with code_cache_capacity=2MB compile_threshold=1000
  11-10 10:49:40.219    2704-2704/teslicinfo.teslic W/System﹕ ClassLoader referenced unknown path: /data/app/teslicinfo.teslic-2/lib/x86
  11-10 10:49:40.547    2704-2717/teslicinfo.teslic I/art﹕ Background partial concurrent mark sweep GC freed 81(3KB) AllocSpace objects, 0(0B) LOS objects, 38% free, 6MB/10MB, paused 1.464ms total 120.600ms
  11-10 10:49:40.677    2704-2713/teslicinfo.teslic W/art﹕ Suspending all threads took: 16.632ms
  11-10 10:49:40.742    2704-2717/teslicinfo.teslic I/art﹕ Background sticky concurrent mark sweep GC freed 21(864B) AllocSpace objects, 0(0B) LOS objects, 0% free, 21MB/21MB, paused 1.278ms total 117.549ms
  11-10 10:49:40.926    2704-2724/teslicinfo.teslic D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
  11-10 10:49:40.972    2704-2704/teslicinfo.teslic D/﹕ HostConnection::get() New Host Connection established 0xab9908d0, tid 2704
  11-10 10:49:41.045    2704-2724/teslicinfo.teslic D/﹕ HostConnection::get() New Host Connection established 0xab990dd0, tid 2724
  11-10 10:49:41.066    2704-2724/teslicinfo.teslic I/OpenGLRenderer﹕ Initialized EGL, version 1.4
  11-10 10:49:41.151    2704-2724/teslicinfo.teslic W/EGL_emulation﹕ eglSurfaceAttrib not implemented
  11-10 10:49:41.151    2704-2724/teslicinfo.teslic W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xad92c960, error=EGL_SUCCESS
  11-10 10:49:44.407    2704-2724/teslicinfo.teslic W/EGL_emulation﹕ eglSurfaceAttrib not implemented
  11-10 10:49:44.407    2704-2724/teslicinfo.teslic W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xac13e200, error=EGL_SUCCESS
  11-10 10:49:44.893    2704-2724/teslicinfo.teslic E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xab9ac980
  11-10 10:49:46.143    2704-2717/teslicinfo.teslic W/art﹕ Suspending all threads took: 13.446ms
  11-10 10:49:46.147    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
  11-10 10:49:46.147    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
  11-10 10:49:46.149    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
  11-10 10:49:46.149    2704-2704/teslicinfo.teslic I/art﹕ Clamp target GC heap from 34MB to 32MB
  11-10 10:49:46.149    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
  11-10 10:49:46.178    2704-2704/teslicinfo.teslic I/art﹕ Clamp target GC heap from 34MB to 32MB
  11-10 10:49:46.178    2704-2704/teslicinfo.teslic I/art﹕ Alloc concurrent mark sweep GC freed 267(24KB) AllocSpace objects, 0(0B) LOS objects, 3% free, 30MB/32MB, paused 1.195ms total 27.810ms
  11-10 10:49:46.182    2704-2704/teslicinfo.teslic I/art﹕ Forcing collection of SoftReferences for 1447KB allocation
  11-10 10:49:46.182    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
  11-10 10:49:46.195    2704-2704/teslicinfo.teslic I/art﹕ Clamp target GC heap from 34MB to 32MB
  11-10 10:49:46.195    2704-2704/teslicinfo.teslic I/art﹕ Alloc concurrent mark sweep GC freed 11(344B) AllocSpace objects, 0(0B) LOS objects, 3% free, 30MB/32MB, paused 3.038ms total 12.420ms
  11-10 10:49:46.198    2704-2704/teslicinfo.teslic W/art﹕ Throwing OutOfMemoryError "Failed to allocate a 1481772 byte allocation with 1096520 free bytes and 1070KB until OOM"
  11-10 10:49:46.198    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
  11-10 10:49:46.199    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
  11-10 10:49:46.199    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
  11-10 10:49:46.199    2704-2704/teslicinfo.teslic I/art﹕ Clamp target GC heap from 34MB to 32MB
  11-10 10:49:46.199    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
  11-10 10:49:46.211    2704-2704/teslicinfo.teslic I/art﹕ Clamp target GC heap from 34MB to 32MB
  11-10 10:49:46.211    2704-2704/teslicinfo.teslic I/art﹕ Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 3% free, 30MB/32MB, paused 0 total 10.985ms
  11-10 10:49:46.214    2704-2704/teslicinfo.teslic I/art﹕ Forcing collection of SoftReferences for 1447KB allocation
  11-10 10:49:46.214    2704-2704/teslicinfo.teslic I/art﹕ Starting a blocking GC Alloc
  11-10 10:49:46.227    2704-2704/teslicinfo.teslic I/art﹕ Clamp target GC heap from 34MB to 32MB
  11-10 10:49:46.227    2704-2704/teslicinfo.teslic I/art﹕ Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 3% free, 30MB/32MB, paused 1.276ms total 12.712ms
  11-10 10:49:46.229    2704-2704/teslicinfo.teslic W/art﹕ Throwing OutOfMemoryError "Failed to allocate a 1481772 byte allocation with 1096520 free bytes and 1070KB until OOM"
  11-10 10:49:46.231    2704-2704/teslicinfo.teslic D/skia﹕ --- allocation failed for scaled bitmap
  11-10 10:49:46.233    2704-2704/teslicinfo.teslic D/AndroidRuntime﹕ Shutting down VM
  11-10 10:49:46.233    2704-2704/teslicinfo.teslic E/AndroidRuntime﹕ FATAL EXCEPTION: main
  Process: teslicinfo.teslic, PID: 2704
  java.lang.OutOfMemoryError: Failed to allocate a 1481772 byte allocation with 1096520 free bytes and 1070KB until OOM
          at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
          at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
          at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
          at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
          at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
          at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
          at android.content.res.Resources.loadDrawable(Resources.java:2540)
          at android.content.res.Resources.getDrawable(Resources.java:806)
          at android.content.Context.getDrawable(Context.java:458)
          at android.widget.ImageView.resolveUri(ImageView.java:811)
          at android.widget.ImageView.setImageResource(ImageView.java:418)
          at teslicinfo.teslic.diskotekeActivity.diskoteke_dzungla(diskotekeActivity.java:21)
          at teslicinfo.teslic.diskotekeActivity.onCreate(diskotekeActivity.java:437)
          at android.app.Activity.performCreate(Activity.java:6237)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
          at android.app.ActivityThread.-wrap11(ActivityThread.java)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:148)
          at android.app.ActivityThread.main(ActivityThread.java:5417)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  11-10 10:49:47.991    2704-2704/? I/Process﹕ Sending signal. PID: 2704 SIG: 9
  </code></pre>