title: Java - Android app skipping 400+ frames
body: <p>When I run my app, it takes a very long time to load up. When it starts it is pretty laggy. When I am running my code I am getting this message in my logcat:</p>
  
  <pre><code>06-28 03:36:22.969: I/Choreographer(1506): Skipped 453 frames!  The application may be doing too much work on its main thread.
  </code></pre>
  
  <p>I am thinking there is some kind of code in my main file that is slowing this whole thing down because it didn't do this for the longest time.  Also the fact that its skipping 453 frames means somethings not right.</p>
  
  <p>Here is my code, its about 1000 lines so If anyone wants to read through it that would be awesome but if not if I could get lead into the direction of fixing this problem that would be great.</p>
  
  <pre><code>public class PlayScreen extends View {
  
  // Constructor
  public PlayScreen(Context context) {
      super(context);
  
      /**
       * Instantiate all variables.
       */
  
      playerBounds = new RectF();
      rowBlock = new RectF();
      rowBlock2 = new RectF();
      startPlaying = new RectF();
      continuePlaying = new RectF();
      rowGlow = new RectF();
      rowGlow2 = new RectF();
      menuBox = new RectF();
      continueplayingBounds = new RectF();
  
      meteorBounds = new RectF();
      pointLossBounds = new RectF();
      pointGainBounds = new RectF();
      speedBounds = new RectF();
  
      titleBounds = new RectF();
      playBounds = new RectF();
  
      doublePointsBounds = new RectF();
      bulletBounds = new RectF();
      ghostWallBounds = new RectF();
      wideGapsBounds = new RectF();
  
  
      ///// Colors /////
  
      colorGreen = new Paint();
      colorBlack = new Paint();
      colorWhite = new Paint();
      colorBlue = new Paint();
      colorYellow = new Paint();
      colorRed = new Paint();
      colorCyan = new Paint();
      colorMagenta = new Paint();
      colorOrange = new Paint();
  
  
      glowGreen = new Paint();
      glowWhite = new Paint();
      glowBlue = new Paint();
      glowYellow = new Paint();
      glowRed = new Paint();
      glowCyan = new Paint();
      glowMagenta = new Paint();
      glowOrange = new Paint();
      glowBlack = new Paint();
  
      translucentGrey = new Paint();
  
      transparent = new Paint();
      boostPaint = new Paint();
      countPaint = new Paint();
  
      align = null;
  
      // Set my basic color's
      colorGreen.setColor(Color.rgb(17, 255, 0));        
      colorBlack.setColor(Color.rgb(0, 0, 0));
      colorWhite.setColor(Color.rgb(255, 255, 255));
      colorBlue.setColor(Color.rgb(0, 0, 255));
      colorYellow.setColor(Color.rgb(243, 243, 21));
      colorRed.setColor(Color.rgb(255, 0, 0));
      colorCyan.setColor(Color.rgb(51, 255, 255));
      colorMagenta.setColor(Color.rgb(255, 0, 255));
      colorOrange.setColor(Color.rgb(255, 119, 0));
      transparent.setColor(Color.TRANSPARENT);
  
      // Set glow colors
      glowGreen.setColor(Color.argb(150, 17, 255, 0)); 
      glowWhite.setColor(Color.argb(150, 255, 255, 255));
      glowBlue.setColor(Color.argb(150, 0, 0, 255));
      glowYellow.setColor(Color.argb(150, 243, 243, 21));
      glowRed.setColor(Color.argb(150, 255, 0, 0));
      glowCyan.setColor(Color.argb(150, 51, 255, 255));
      glowMagenta.setColor(Color.argb(150, 255, 0, 255));
      glowOrange.setColor(Color.argb(150, 255, 119, 0));
      glowBlack.setColor(Color.argb(100, 0, 0, 0));
  
      translucentGrey.setColor(Color.argb(100, 205, 201, 201));
  
      lobsterFont = Typeface.createFromAsset(Assets, "fonts/Lobster.otf");
  
      countPaint.setColor(Color.rgb(255, 255, 255));
      countPaint.setTextSize(60);
      countPaint.setTextAlign(align.RIGHT);
      countPaint.setTypeface(lobsterFont);
  
      boostPaint.setColor(Color.rgb(255, 255, 255));
      boostPaint.setTextSize(40);
      boostPaint.setTextAlign(align.CENTER);
      boostPaint.setTypeface(lobsterFont);
  
  
      ///// End Colors /////
  
      timer = new Timer();
  
  
      random = new Random();
      Playing = false;
      event = random.nextInt(4);
      boost = random.nextInt(4);
  
      clock();
  
  
  
      box = BitmapFactory.decodeResource(getResources(), R.drawable.box);
  
      play = BitmapFactory.decodeResource(getResources(), R.drawable.start);
      title = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
  
  
      ballBlue = BitmapFactory.decodeResource(getResources(), R.drawable.ballblue);
      ballRed = BitmapFactory.decodeResource(getResources(), R.drawable.ballred);
      ballYellow = BitmapFactory.decodeResource(getResources(), R.drawable.ballyellow);
      ballGreen = BitmapFactory.decodeResource(getResources(), R.drawable.ballgreen);
  
      dp = BitmapFactory.decodeResource(getResources(), R.drawable.dp);
      wg = BitmapFactory.decodeResource(getResources(), R.drawable.widegaps);
      rocket = BitmapFactory.decodeResource(getResources(), R.drawable.rocket);
      ghost = BitmapFactory.decodeResource(getResources(), R.drawable.ghost);
  
  
  
      // Get window size and save it to screenWidth and screenHeight.
      WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
      Display display = wm.getDefaultDisplay();
      Point size = new Point();
      display.getSize(size); 
      screenWidth = size.x;
      screenHeight = size.y;
  
      density = getResources().getDisplayMetrics().density;
  
      rowSpace = (int) (100 * density);
  
      boostdiam = (int) (25 * density);
  
      int nor = screenHeight / rowSpace; // Number of rows to be displayed.
  
      /**
       * Generate rows and gaps at set intervals.
       * Chooses a random color for each row.
       */
      for (int row = 0; row &lt; nor + 1; row ++) { 
          final int gap = (int) (random.nextInt(maxGap) + minGap * density);
          final int block = random.nextInt(screenWidth - gap);
  
          blockY[row] = screenHeight * 1/2 + row * rowSpace; // Positions first block at center screen.
          blockX1[row] = block;
          blockX2[row] = block + gap; 
          blockcolor[row] = random.nextInt(8);
  
          passedrow[row] = false;
  
          halfgap = (float) (blockX2[0] + blockX1[0]) / 2; // Used for centering start button to first gap.           
  
      }
  
  
      randomEvent = System.currentTimeMillis() + random.nextInt(EventTimeMax) + EventTimeMin;
      randomBoost = System.currentTimeMillis() + random.nextInt(BoostTimeMax) + BoostTimeMin;
      eventRandomX = random.nextInt(screenWidth);
  
      meteorBounds.set(eventRandomX * density, -50 * density, eventRandomX + 50 * density, 0 * density);
      pointLossBounds.set(eventRandomX * density, -50 * density, eventRandomX + 50 * density, 0 * density);
      pointGainBounds.set(eventRandomX * density, -50 * density, eventRandomX + 50 * density, 0 * density);
      speedBounds.set(eventRandomX * density, -50 * density, eventRandomX + 50 * density, 0 * density);
  
  
      System.out.println(density);
  
      scoreText = score.toString();
  
  }
  
  // Called back to draw the view. Also called by invalidate().
  @Override
  protected void onDraw(Canvas canvas) {
  
  
  
  
      // Once game is started and paused is set to true, pause all counters.          
      if (Playing == true &amp;&amp; rocketboostOn == false) { 
          scrollSpeed = oldSpeed;
          scrollSpeed -= scrollInterval;
          oldSpeed = scrollSpeed;
      }
  
      int rowBlockHeight = screenHeight / 32;
  
      playerBounds.set(playerX - playerRadius * density, (float) playerY - playerRadius * density, playerX + playerRadius * density, (float) playerY + playerRadius * density);
  
      int nor = screenHeight / rowSpace;
  
      for (int row = 0; row &lt; nor + 1; row ++) {              
          blockY[row] = blockY[row] + scrollSpeed;
  
          rowBlock.set(0, (float) blockY[row],(float) blockX1[row], (float) blockY[row] + rowBlockHeight);
          rowBlock2.set((float) blockX2[row], (float)blockY[row], (float) screenWidth, (float) blockY[row] + rowBlockHeight);
  
          rowGlow.set(-20, (float) blockY[row] - 10, (float) blockX1[row] + 10, (float) blockY[row] + rowBlockHeight + 10);
          rowGlow2.set((float) blockX2[row] - 10, (float) blockY[row] - 10, (float) screenWidth + 20, (float) blockY[row] + rowBlockHeight + 10);
  
          if (blockY[row] &lt; screenHeight) {
  
              if (blockcolor[row] == 0 &amp;&amp; gwboostOn == false) {
                  canvas.drawRoundRect(rowGlow, 4 * density, 4 * density, glowGreen);
                  canvas.drawRoundRect(rowGlow2, 4 * density, 4 * density, glowGreen);                    
                  if (rocketboostOn == false) {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, colorBlack);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, colorBlack);
                  } else {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, translucentGrey);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, translucentGrey);
                  }
              }
              if (blockcolor[row] == 1 &amp;&amp; gwboostOn == false) {
                  canvas.drawRoundRect(rowGlow, 4 * density, 4 * density, glowRed);
                  canvas.drawRoundRect(rowGlow2, 4 * density, 4 * density, glowRed); 
                  if (rocketboostOn == false) {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, colorBlack);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, colorBlack);
                  } else {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, translucentGrey);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, translucentGrey);
                  }
              }
              if (blockcolor[row] == 2 &amp;&amp; gwboostOn == false) {
                  canvas.drawRoundRect(rowGlow, 4 * density, 4 * density, glowBlue);
                  canvas.drawRoundRect(rowGlow2, 4 * density, 4 * density, glowBlue);
                  if (rocketboostOn == false) {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, colorBlack);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, colorBlack);
                  } else {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, translucentGrey);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, translucentGrey);
                  }          
              }
              if (blockcolor[row] == 3 &amp;&amp; gwboostOn == false) {
                  canvas.drawRoundRect(rowGlow, 4 * density, 4 * density, glowWhite);
                  canvas.drawRoundRect(rowGlow2, 4 * density, 4 * density, glowWhite);
                  if (rocketboostOn == false) {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, colorBlack);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, colorBlack);
                  } else {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, translucentGrey);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, translucentGrey);
                  }                   
              }
              if (blockcolor[row] == 4 &amp;&amp; gwboostOn == false) {
                  canvas.drawRoundRect(rowGlow, 4 * density, 4 * density, glowYellow);
                  canvas.drawRoundRect(rowGlow2, 4 * density, 4 * density, glowYellow);
                  if (rocketboostOn == false) {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, colorBlack);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, colorBlack);
                  } else {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, translucentGrey);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, translucentGrey);
                  }                    
              }     
              if (blockcolor[row] == 5 &amp;&amp; gwboostOn == false) {
                  canvas.drawRoundRect(rowGlow, 4 * density, 4 * density, glowCyan);
                  canvas.drawRoundRect(rowGlow2, 4 * density, 4 * density, glowCyan);
                  if (rocketboostOn == false) {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, colorBlack);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, colorBlack);
                  } else {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, translucentGrey);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, translucentGrey);
                  }                   
              }   
              if (blockcolor[row] == 6 &amp;&amp; gwboostOn == false) {
                  canvas.drawRoundRect(rowGlow, 4 * density, 4 * density, glowMagenta);
                  canvas.drawRoundRect(rowGlow2, 4 * density, 4 * density, glowMagenta);
                  if (rocketboostOn == false) {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, colorBlack);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, colorBlack);
                  } else {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, translucentGrey);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, translucentGrey);
                  }               
              }
              if (blockcolor[row] == 7 &amp;&amp; gwboostOn == false) {
                  canvas.drawRoundRect(rowGlow, 4 * density, 4 * density, glowOrange);
                  canvas.drawRoundRect(rowGlow2, 4 * density, 4 * density, glowOrange);
                  if (rocketboostOn == false) {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, colorBlack);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, colorBlack);
                  } else {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, translucentGrey);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, translucentGrey);
                  }   
              }
              if (gwboostOn == true) {
                  canvas.drawRoundRect(rowBlock, 3 * density, 3 * density, translucentGrey);
                  canvas.drawRoundRect(rowBlock2, 3 * density, 3 * density, translucentGrey);
              }
          }
  
  
          if (blockY[row] &lt; 0) {
  
              final int gap = (int) (random.nextInt(maxGap) + minGap * density);
              final int block = random.nextInt(screenWidth - gap);
  
              if (row == 0) {
                  blockY[row] = blockY[nor] + rowSpace + rowBlockHeight;
              } else {
                  blockY[row] = blockY[row - 1] + rowSpace;
              }
  
              blockX1[row] = block;
              blockX2[row] = block + gap;
              blockcolor[row] = random.nextInt(8);
              passedrow[row] = false;
  
          }
  
          if (passedrow[row] == false) {
  
              if (playerBounds.top &gt; blockY[row]) {
                  passedrow[row] = true;
                  score += 1;
                  scoreText = score.toString();
  
                  if (dpboostOn == true) score += 2;
  
              }
  
          }
  
  
          if (playerBounds.bottom &gt; rowBlock.top &amp;&amp; playerBounds.top &lt; rowBlock.bottom &amp;&amp; (playerBounds.left &lt; blockX1[row] || playerBounds.right &gt; blockX2[row]) &amp;&amp; rocketboostOn == false &amp;&amp; gwboostOn == false) {
                  youLose();                  
          }
  
          if (doublePointsOn == true &amp;&amp; dpboostOn == false) {
              doublePointsBounds.set(boostIconX, (float) blockY[boostIconRow] - boostdiam - 20, doublePointsBounds.left + boostdiam, doublePointsBounds.top + boostdiam);
  
              canvas.drawBitmap(dp, null, doublePointsBounds, null);
  
              if (hasCollided(doublePointsBounds.left, doublePointsBounds.top, doublePointsBounds.right, doublePointsBounds.bottom)) {    
                  boostTime = 10;
                  dpboostOn = true;                       
              }
  
              if (doublePointsBounds.bottom &lt; 0) {
                  doublePointsOn = false;
                  randomBoost = System.currentTimeMillis() + random.nextInt(BoostTimeMax) + BoostTimeMin;
              }
          }
  
          if(dpboostOn == true &amp;&amp; rocketboostOn == false &amp;&amp; wgboostOn == false &amp;&amp; gwboostOn == false) {
              scoreInt = 2;
  
              if(boostTime &lt; 1) {
                  dpboostOn = false;
                  doublePointsOn = false;
                  randomBoost = System.currentTimeMillis() + random.nextInt(BoostTimeMax) + BoostTimeMin;
                  scoreInt = 1;
  
              } else {
                  canvas.drawText("Double Points", screenWidth / 2, 25 * density, boostPaint);
                  canvas.drawText(boostTime.toString(), screenWidth / 2, 55 * density, countPaint);
              }
          }
  
  
  
  
  
          if (rocketOn == true &amp;&amp; rocketboostOn == false) {
  
              bulletBounds.set(boostIconX, (float) blockY[boostIconRow] - boostdiam - 20, bulletBounds.left + boostdiam, bulletBounds.top + boostdiam);
              canvas.drawBitmap(rocket, null, bulletBounds, null);
  
              if (hasCollided(bulletBounds.left, bulletBounds.top, bulletBounds.right, bulletBounds.bottom)) {    
                  boostTime = 5;
                  oldSpeed = scrollSpeed;
  
                  rocketboostOn = true;                       
              }
  
              if (bulletBounds.bottom &lt; 0) {
                  rocketOn = false;
                  randomBoost = System.currentTimeMillis() + random.nextInt(BoostTimeMax) + BoostTimeMin; 
              }
  
          }
  
          if (rocketboostOn == true &amp;&amp; dpboostOn == false &amp;&amp; wgboostOn == false &amp;&amp; gwboostOn == false) {
  
              scrollSpeed = oldSpeed * 1.5;
  
  
              if(boostTime &lt; 1) {
                  rocketboostOn = false;
                  rocketOn = false;
                  randomBoost = System.currentTimeMillis() + random.nextInt(BoostTimeMax) + BoostTimeMin;
                  scrollSpeed = oldSpeed;
  
              } else {
                  canvas.drawText("Rocket", screenWidth / 2, 25 * density, boostPaint);
                  canvas.drawText(boostTime.toString(), screenWidth / 2, 55 * density, countPaint);
              }
          }
  
  
  
          if (widegapsOn == true &amp;&amp; wgboostOn == false) {
  
              wideGapsBounds.set(boostIconX, (float) blockY[boostIconRow] - boostdiam - 20, wideGapsBounds.left + boostdiam, wideGapsBounds.top + boostdiam);
              canvas.drawBitmap(wg, null, wideGapsBounds, null);
  
              if (hasCollided(wideGapsBounds.left, wideGapsBounds.top, wideGapsBounds.right, wideGapsBounds.bottom)) {    
                  boostTime = 10;
                  wgboostOn = true;                       
              }
  
              if (wideGapsBounds.top &lt; 0) {
                  widegapsOn = false;
                  randomBoost = System.currentTimeMillis() + random.nextInt(BoostTimeMax) + BoostTimeMin; 
              }
  
          }
  
          if (wgboostOn == true &amp;&amp; rocketboostOn == false &amp;&amp; dpboostOn == false &amp;&amp; gwboostOn == false) {                      
  
              minGap = 200;
              maxGap = 250;
  
              if(boostTime &lt; 1) {
                  wgboostOn = false;
                  widegapsOn = false;
  
                  minGap = 100;
                  maxGap = 150;
                  randomBoost = System.currentTimeMillis() + random.nextInt(BoostTimeMax) + BoostTimeMin;
  
              } else {
                  canvas.drawText("Wide Gaps", screenWidth / 2, 25 * density, boostPaint);
                  canvas.drawText(boostTime.toString(), screenWidth / 2, 55 * density, countPaint);
              }
          }
  
  
          if (ghostWallOn == true &amp;&amp; gwboostOn == false) {
  
              ghostWallBounds.set(boostIconX, (float) blockY[boostIconRow] - boostdiam - 20, ghostWallBounds.left + boostdiam, ghostWallBounds.top + boostdiam);
              canvas.drawBitmap(ghost, null, ghostWallBounds, null);
  
              if (hasCollided(ghostWallBounds.left, ghostWallBounds.top, ghostWallBounds.right, ghostWallBounds.bottom)) {    
                  gwboostOn = true;
                  boostTime = 10;
  
              }
  
              if (ghostWallBounds.top &lt; 0) {
                  ghostWallOn = false;
                  randomBoost = System.currentTimeMillis() + random.nextInt(BoostTimeMax) + BoostTimeMin;
              }
  
  
          }
  
          if(gwboostOn == true &amp;&amp; rocketboostOn == false &amp;&amp; wgboostOn == false &amp;&amp; dpboostOn == false) {
  
  
  
              if(boostTime &lt; 1) {
                  gwboostOn = false;
                  ghostWallOn = false;
                  randomBoost = System.currentTimeMillis() + random.nextInt(BoostTimeMax) + BoostTimeMin;
  
              } else {
                  canvas.drawText("Ghost Walls", screenWidth / 2, 25 * density, boostPaint);
                  canvas.drawText(boostTime.toString(), screenWidth / 2, 55 * density, countPaint);
              }
          }
  
      } // End of main FOR loop
      //canvas.drawText(scrollSpeed.toString(), 200, 200, scoreColor);
  
      if (score &lt; 0) {
          youLose();
      }
  
      int playHeight=87; int playWidth=96;
      playBounds.set(halfgap - playWidth / 2 * density, (float) (blockY[0] - rowSpace), halfgap + playWidth / 2 * density, playBounds.top + playHeight * density);
  
      playerBounds.set(playerX - playerRadius * density,(float) playerY - playerRadius * density, playerX + playerRadius * density, (float) playerY + playerRadius * density);
  
      canvas.drawOval(playerBounds, transparent); // Draw player
  
      if (Playing == true) canvas.drawText(scoreText, 350 * density, 30 * density, countPaint);
  
  
      int titleWidth = 256; int titleHeight = 76; 
      titleBounds.set(screenWidth / 2 - titleWidth / 2 * density, 10 * density, titleBounds.left + titleWidth * density, titleBounds.top + titleHeight * density);
  
  
      if (Playing == false) {
          canvas.drawBitmap(play, null, playBounds, null);    
          canvas.drawBitmap(title, null, titleBounds, null);
      }   
  
  
      //change to 10          // Events // 
      if (score &gt; 0 &amp;&amp; System.currentTimeMillis() &gt; randomEvent) {
  
  
          if (meteorOn == false &amp;&amp; pointLossOn == false &amp;&amp; pointGainOn == false &amp;&amp; speedEventOn == false) {
  
  
              event = random.nextInt(4);              
              eventY = random.nextInt(15) + 5;
  
              if (event == 0) {
                  meteorOn = true;
              } else if (event == 1) {
                  pointLossOn = true;
              } else if (event == 2) {
                  pointGainOn = true;
              } else if (event == 3) {
                  speedEventOn = true;
              }                   
  
          }
  
  
  
          if (meteorOn == true) {
              MeteorEvent(5, eventY);
              if (meteorBounds.centerX() &lt; screenWidth &amp;&amp; meteorBounds.centerY() &lt; screenHeight &amp;&amp; meteorBounds.centerX() &gt; 0) {
                  canvas.drawBitmap(ballRed, null, meteorBounds, null);
              }   
          }
  
          if (pointLossOn == true) {
              PointLossEvent(5, eventY);
              if (pointLossBounds.centerX() &lt; screenWidth &amp;&amp; pointLossBounds.centerY() &lt; screenHeight &amp;&amp; pointLossBounds.centerX() &gt; 0) {
                  canvas.drawBitmap(ballBlue, null, pointLossBounds, null);
              }
          }
          if (pointGainOn == true) {
              PointGainEvent(5, eventY);
              if (pointGainBounds.centerX() &lt; screenWidth &amp;&amp; pointGainBounds.centerY() &lt; screenHeight &amp;&amp; pointGainBounds.centerX() &gt; 0) {
                  canvas.drawBitmap(ballGreen, null, pointGainBounds, null);
              }
          }
          if (speedEventOn == true) {
              SpeedEvent(5, eventY);
              if (speedBounds.centerX() &lt; screenWidth &amp;&amp; speedBounds.centerY() &lt; screenHeight &amp;&amp; speedBounds.centerX() &gt; 0) {
                  canvas.drawBitmap(ballYellow, null, speedBounds, null);
              }
          }
  
  
  
      } // End of events //
  
  
      // change to 20
      if (score &gt; 0 &amp;&amp; System.currentTimeMillis() &gt; randomBoost) {
  
          if (doublePointsOn == false &amp;&amp; rocketOn == false &amp;&amp; widegapsOn == false &amp;&amp; ghostWallOn == false) {
  
              boost = random.nextInt(4); 
  
              System.out.println(boost);
              //boostIconRow = random.nextInt(nor) + nor / 2;
              boostIconRow = 1;
              boostIconX = random.nextInt((int) (screenWidth - 50 * density)) + 50;
  
              if (boost == 0) {
                  doublePointsOn = true;
              } else if (boost == 1) {
                  rocketOn = true;
              } else if (boost == 2) {
                  widegapsOn = true;
              } else if (boost == 3) {
                  ghostWallOn = true;
              }
  
              System.out.println(ghostWallOn);
          }
  
      }
  
      //canvas.drawBitmap(play, null, playBounds, null);        
  
  
      if(score &gt; 50) {
          EventTimeMax = 4000;
          EventTimeMin = 2000;         
      } else if (score &gt; 100) {   
          EventTimeMax = 3000;
          EventTimeMin = 1000;    
      } else if (score &gt; 250) {
          EventTimeMax = 2000; 
          EventTimeMin = 1000;
      }
  
  
  
      // Delay    
      try { Thread.sleep(10); }
      catch (InterruptedException e){}
      invalidate(); // Force a re-draw
  }
  
  public void clock() {
  
      timer.schedule(new TimerTask() {
  
          @Override
          public void run() {
  
              if (boostTime &gt; 0) {
                  boostTime -= 1;
              } 
  
          }
  
      }, 0, 1000);   
  
  }
  
  // Called back when the view is first created or its size changes.
  @Override public void onSizeChanged(int w, int h, int oldW, int oldH) {
  
      // Set the movement bounds for the ball
      xViewMax = w - 1;
      yViewMax = h - 1;
  
  }
  
  
  public void highscoreSaver() {
  
      if(finalScore &gt; MainActivity.prefs.getInt("HighScore", 0)) {
          MainActivity.prefsEditor = MainActivity.prefs.edit();
          MainActivity.prefsEditor.putInt("HighScore", score);
          MainActivity.prefsEditor.commit();
  
      }
  
  }
  
  public void youLose() {
  
      View LoseScreen = new LoseScreen(getContext());
      ViewGroup parent = (ViewGroup) getParent();
      finalScore = score;
  
      highscoreSaver();
  
      timer.cancel();
  
      parent.addView(LoseScreen);
      parent.removeView(this);
      parent.setBackgroundResource(R.drawable.bg);
  
  }
  
  public void MeteorEvent(float slopeX, float slopeY) {
  
      if (eventRandomX &lt; screenWidth / 2) {
      meteorBounds.left += slopeX; meteorBounds.right += slopeX;
      } else {
      meteorBounds.left -= slopeX; meteorBounds.right -= slopeX;
      }
      meteorBounds.top += slopeY; meteorBounds.bottom += slopeY;
  
      if (!(meteorBounds.centerX() &lt; screenWidth &amp;&amp; meteorBounds.centerY() &lt; screenHeight &amp;&amp; meteorBounds.centerX() &gt; 0)) {
  
          randomEvent = System.currentTimeMillis() + random.nextInt(EventTimeMax) + EventTimeMin;
          eventRandomX = random.nextInt(screenWidth - 20) + 20;
          meteorBounds.set(eventRandomX * density, -50 * density, eventRandomX + 50 * density, 0 * density);  
          meteorOn = false;
      }   
      if (hasCollided(meteorBounds.left, meteorBounds.top, meteorBounds.right, meteorBounds.bottom))  
          youLose();
  }
  
  
  public boolean hasCollided (float left, float top, float right, float bottom) {
  
      if (((playerBounds.bottom &gt; top &amp;&amp; playerBounds.bottom &lt; bottom) || (playerBounds.top &lt; bottom &amp;&amp; playerBounds.top &gt; top)) 
          &amp;&amp; ((playerBounds.left &gt; left &amp;&amp; playerBounds.left &lt; right) || (playerBounds.right &lt; right &amp;&amp; playerBounds.right &gt; left))) {
  
          return true;        
      } else {    
          return false;
      }
  }
  
  public boolean onTouchEvent(MotionEvent e) {
  
      // Get finger's X and Y position
      float x = e.getX();
      float y = e.getY();
  
      if(x &gt; playBounds.left || x &lt; playBounds.right &amp;&amp; y &lt; playBounds.bottom &amp;&amp; y &gt; playBounds.top) {
  
          Playing = true;         
      }
  
  
      if (Playing == true) {
  
                  switch (e.getAction()) {
  
                  case MotionEvent.ACTION_MOVE:
                      playerX = x;
                      playerY = y;
                      break;
  
                  case MotionEvent.ACTION_UP:
                      youLose();
                  }
              }
  
      return true;
  }
  
  }
  </code></pre>