Android Studio - Activity Call Error

0

I developed an application (game) with buttons that call screens. The idea is like this:

  • Screen 1 - start
  • Screen 2 - choose character
  • Screen 3 - knows object1
  • Screen 4 - play with object1
  • Screen 5 - knows object2
  • Screen 6 - play with object2
  • Screen 7 - knows object3
  • .... follows the pattern ..

When I test the phone, after a certain number of screens (7) the application stops working.

The base of all screens (Activity) are similar (Screens 3,5,7, Screens 4,6,8), changes some items. I have already analyzed the codes and I can not understand them.

I did some testing: starting from certain screens and changing the order of the screens. But the problem continues, when it reaches a certain number of screen advances, the application hangs, presses "Ok" and the screen restarts.

Who can help me, thank you.

    
asked by anonymous 04.09.2017 / 22:40

2 answers

0

1) So you're really having a memory problem, keep that finish scheme after startactivity.

2) Work with the states of your activity.Close this code in your ondestroy, it will clear the memory that your app is consuming with media when the user leaves the podium.

 @Override
protected void onDestroy() {
    if( mp!= null ){
        mp.stop();
        mp.release();
        mp= null;
    }
    super.onDestroy();
}

Consequently apply this code as you are using the sound in your application and the sound is finished,

mp.setOnCompletionListener(new OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
        mp.stop();
        mp.release();
        mp= null;
        }
        });

It would be interesting to insert this code into your build.gradle: It will increase the memory consumption of your application, use it sparingly, run tests ..... It increases the storage capacity of your heap memory, which is where java creates the application objects.     android {      // ....      dexOptions {         javaMaxHeapSize "2g"     } }

    
05.09.2017 / 22:08
0

Your problem lies in stacking Activity over Activity.

Start using Fragments for these cases OR, with each new screen open, you give finish() to finish the previous one (if there is no problem in the UX sequence).

    
06.09.2017 / 02:07