0
\$\begingroup\$

After I decided to create an activity to show the results of the game with try again button. Every 3rd try the game will stop with this error.

java.lang.OutOfMemoryError: Failed to allocate a 3819212 byte allocation with 610080 free bytes and 595KB until OOM

What am I doing wrong here?

My try again button code.

 public void tryAgain(View view) {
    startActivity(new Intent(getApplicationContext(), StartActivity.class));
}

How I call my result activity

Intent intent = new Intent(Constants.CURRENT_CONTEXT.getApplicationContext(), ResultActivity.class);
            intent.putExtra("SCORE", obstacleManager.getScore());
            Constants.CURRENT_CONTEXT.startActivity(intent);
\$\endgroup\$
6
  • \$\begingroup\$ Are you loading an expensive ressource when showing the result? \$\endgroup\$ Feb 3, 2017 at 11:22
  • \$\begingroup\$ @realUser404 I don't know what you mean by expensive resource. But the result only have a text that says game over, the score, the highest score and a button. No flashy design either. \$\endgroup\$
    – realNewbie
    Feb 3, 2017 at 11:24
  • \$\begingroup\$ If you were loading a few MB animation each time, it would have explained the error you are getting. When is the error showing up anyway? When the result shows or when you click "retry"? \$\endgroup\$ Feb 3, 2017 at 11:28
  • \$\begingroup\$ @realUser404 it happens after I click retry. BTW their is an animation in my game. I animated the background and the player. \$\endgroup\$
    – realNewbie
    Feb 3, 2017 at 11:31
  • \$\begingroup\$ In this case I believe it means you are loading the resources each time you retry the game and never unload them, which causes the error \$\endgroup\$ Feb 3, 2017 at 11:44

1 Answer 1

0
\$\begingroup\$

Found a solution on this 1. calling finish() before the starting new intents in every activity solve this issues.

E.g

finish() ;
Intent intent = new Intent(Constants.CURRENT_CONTEXT.getApplicationContext(), ResultActivity.class);
        intent.putExtra("SCORE", obstacleManager.getScore());
        Constants.CURRENT_CONTEXT.startActivity(intent);
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .