Activity GameActivity: The page that’s opened when the application is first opened.
Activity GameMain: The playing activity of the game.
Activity GameWin: Transfers to the next GameActivity (eventually will have a “You win!” screen, with stats and things)
- Application is started
-
This is triggered:
button = (Button) findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Intent intent = new Intent(context, GameMain.class); intent.putExtra("level",1); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); } }); -
GameMainhas now loaded. The character,circle, is now on the left side of the screen. -
When
circlegets to the right side of the screen, this if statement inside my game loop now becomes true:if ((circle.x+width/2 > end.startx) && (circle.x-width/2 < end.stopx) && (circle.y+circle.size==end.starty-width/2)) { layout.removeAllViews(); Intent intent = new Intent(context, GameWin.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("level",level); finish(); startActivity(intent); } -
GameWinscreen does this:Log.v(TAG,"Goint to level: "+(level+1)); Intent intent = new Intent(context, GameMain.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("level",(level+1)); startActivity(intent); finish(); -
Sometimes it works, and goes to
GameMainwith level data as 2, just considerably slower than if I went through the level screen and straight to level2. Sometimes it works, and goes toGameMainwith level data as 2, and reloads the page over and over and over again. Sometimes, my phone restarts. -
If I have the ability to complete level 2, I do so. Level 3 is even slower if it works, or refreshes, or restarts the phone.
-
If I click “Home” at any time, it goes to my home screen but the application opens itself back to the
GameMainwith the last level (back to step 6 or 7).
What am I doing wrong?
API Level 8, LG P500 (2.3.3)
It turns out this wasn’t the problem. The game loop was still running in the background.
It turns out it was only partially the issue of the intent; the main issue was that I wasn’t stopping the gameloop.
When the gameloop stopped, everything worked fine.