Android Studio - Error in Activity Call

Asked

Viewed 401 times

0

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

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

When I will do the tests on mobile, after determined number of screens (7) the application to work.

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

I did some tests: starting from certain screens and changing the order of the screens. But the problem continues, when it arrives at a certain number of screen advances, the application hangs, tightening "Ok" and the screen is restarted.

Anyone who can help me, thank you.

  • send if anything appears in the log, and what appears in the log,

  • Actually it hangs on the cell phone. When I do the tests on the device

  • ue, stick the usb cable on mobile, and emulate the app,will generate an error logging, on android monitor,when the app stop,but I believe it may be some memory problem,maybe

  • What may be happening is a memory overload. There is no possibility of you closing the previous Activity as soon as you open a new one?

  • Put an Activity print there

  • @Otocampos your comment was TOP. I decided to put a Finish() after the call of the new screen. But doing new tests, it came back to hang. I believe it is related to the Media Player, when the user knows the object, he clicks and a sound is emitted using setLooping(true). Then he clicks on the object and the sound stops. However, after some objects, the application hangs, but the sound continues. Any hints?

  • @Dolls symphores was exactly that, I solved with Finish()

  • Guys, I’m back. On my cell phone it is working well all phases (screens). But when I went to put in other phones, the app again gives problem. It stops working on the same screen that stopped on my phone. When it stops, it goes back to home screen, I believe it proves that all previous screens have been completed. Help!

Show 3 more comments

2 answers

0


1)Then really see this having a problem with memory,keep that Finish scheme after startactivity.

2)Work with your Activity states.Put this code on your ondestroy, it will clear the memory your app is consuming with media when the user leaves the patch.

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

Therefore apply this code as you use 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 also insert this code into your build.Radle: It will increase the memory consumption capacity of your application, use it sparingly, do tests.... It increases the storage capacity of your heap memory, which is where java creates the application objects. android{ //.... dexOptions { javaMaxHeapSize "2g" } }

  • Personal thanks by force. @otocampos your tip was ball show. I solved the problem with it.

  • Vlw brother, if you can give an up on the answer,

0

Your Problem Is Staying Stacking Activity On Activity.

Start using Fragments for these cases OR, with each new screen opened, you will give a finish() to end the previous one (in case there is no problem in the sequence of UX).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.