We will do some optimizations to our game by shifting our mainThread after our surface has been created. So, we will remove mainThread = new MainGameThread(getHolder(), this); from our constructor and write it just above the place where we start running it in our surfaceCreated() method, as follows:
@Overridepublic void surfaceCreated(SurfaceHolder holder){ bgImg = new BackgroundImage(BitmapFactory.decodeResource (getResources(), R.drawable.background_image)); playerCharacter = new PlayerCharacter(BitmapFactory.decodeResource (getResources(),R.drawable.player_run),200,246,3); rocks = new ArrayList<Rock>(); upperBoundary = new ArrayList<UpperBoundary>(); lowerBoundary = new ArrayList<LowerBoundary>();