3

When I run my app and press home button and then come back to my app, I get RunTimeException and IllegalStateException errors.

I made a simple Android Alphabet game with sounds where at the end of the game, the amount of time and the number of incorrect are displayed with an OK button to return the user to the main screen. However, when I press the home button and then return to my app to play the game, at the end of the game as soon as the user clicks ok, I get RunTimeException and IllegalStateException errors in the Logcat and the game returns (assuming it's not a restart of my app) to the main page of the game. I looked at several posts here (like here) and tried those solutions, but I still get the following errors. I'm also new and don't know how those solutions relate to my code. Any help is greatly appreciated.

/

/ Display the game over results dialog box
    public void showGameOverDialog(){
        ViewGroup viewGroup = findViewById(android.R.id.content);

        View dialogView = LayoutInflater.from(this).inflate(R.layout.game_over_dialog, viewGroup, false);

        dialog = new AlertDialog.Builder(this);

        dialog.setView(dialogView);
        TextView mTextView_Mistakes = dialogView.findViewById(R.id.textView_Mistakes);
        String temp = getResources().getString(R.string.mistakes) + incorrectCount;
        mTextView_Mistakes.setText(temp);

        TextView mTextView_timeUsed = dialogView.findViewById(R.id.textView_timeUsedText);
        String temp2 = getResources().getString(R.string.time_used) + mTimeUsed;
        mTextView_timeUsed.setText(temp2);

        final AlertDialog alertDialog = dialog.create();
        final Intent intent = new Intent(this, MainActivity.class);
        final Button btnReturnToHome = dialogView.findViewById(R.id.button_return_to_home);
        btnReturnToHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mBackground.release();
                mCorrect.release();
                mWrong.release();
                startActivity(intent);
                finish();                 // <-- put this based on a suggestion in a post in this website
            }
        });
        alertDialog.show();
    }


    @Override
    protected void onPause() {
        super.onPause();
        Log.wtf("OnPause is executed--------------------", "<----------");
        mBackground.reset();
        mCorrect.reset();
        mWrong.reset();

    }
    @Override
    protected void onResume() {
        super.onResume();
        Log.wtf("OnResume is executed--------------------", "<----------");
        if (noResumeFirstTime){  // This makes sure that the following mediaplayers are not started here too.
            Log.wtf("Music started on resume--------------------", "<----------");
            mBackground.start(); // <-- Line 365 is here ------------------
            mCorrect.start();
            mWrong.start();
        }
        noResumeFirstTime = true;
    }

The app is expected to return to the main activity without a glitch, but I get the following errors.

2019-07-28 22:11:58.925 12873-12873/com.example.alphabetsforkids E/lphabetsforkid: Unknown bits set in runtime_flags: 0x8000
2019-07-28 22:12:00.003 12873-12897/com.example.alphabetsforkids E/vndksupport: Could not load /vendor/lib/egl/libGLES_emulation.so from sphal namespace: dlopen failed: library "/vendor/lib/egl/libGLES_emulation.so" not found.
2019-07-28 22:12:00.004 12873-12897/com.example.alphabetsforkids E/libEGL: load_driver(/vendor/lib/egl/libGLES_emulation.so): unknown
2019-07-28 22:12:02.358 12873-12896/com.example.alphabetsforkids E/EGL_emulation: tid 12896: eglQueryString(923): error 0x3008 (EGL_BAD_DISPLAY)
2019-07-28 22:13:42.203 13035-13061/com.example.alphabetsforkids E/vndksupport: Could not load /vendor/lib/egl/libGLES_emulation.so from sphal namespace: dlopen failed: library "/vendor/lib/egl/libGLES_emulation.so" not found.
2019-07-28 22:13:42.203 13035-13061/com.example.alphabetsforkids E/libEGL: load_driver(/vendor/lib/egl/libGLES_emulation.so): unknown
2019-07-28 22:13:43.663 13035-13060/com.example.alphabetsforkids E/EGL_emulation: tid 13060: eglQueryString(923): error 0x3008 (EGL_BAD_DISPLAY)
2019-07-28 22:13:47.845 13035-13035/com.example.alphabetsforkids E/OnResume is executed--------------------: <----------
2019-07-28 22:14:00.320 13035-13035/com.example.alphabetsforkids E/OnPause is executed--------------------: <----------
2019-07-28 22:14:05.848 13035-13035/com.example.alphabetsforkids E/OnResume is executed--------------------: <----------
2019-07-28 22:14:05.882 13035-13035/com.example.alphabetsforkids E/Music started on resume--------------------: <----------
2019-07-28 22:14:05.925 13035-13035/com.example.alphabetsforkids E/MediaPlayerNative: start called in state 1, mPlayer(0x0)
2019-07-28 22:14:05.925 13035-13035/com.example.alphabetsforkids E/MediaPlayerNative: error (-38, 0)
2019-07-28 22:14:05.927 13035-13035/com.example.alphabetsforkids E/MediaPlayerNative: start called in state 1, mPlayer(0x0)
2019-07-28 22:14:05.928 13035-13035/com.example.alphabetsforkids E/MediaPlayerNative: error (-38, 0)
2019-07-28 22:14:05.929 13035-13035/com.example.alphabetsforkids E/MediaPlayerNative: start called in state 1, mPlayer(0x0)
2019-07-28 22:14:05.930 13035-13035/com.example.alphabetsforkids E/MediaPlayerNative: error (-38, 0)
2019-07-28 22:14:06.828 13035-13035/com.example.alphabetsforkids E/MediaPlayer: Error (-38,0)
2019-07-28 22:14:06.831 13035-13035/com.example.alphabetsforkids E/MediaPlayer: Error (-38,0)
2019-07-28 22:14:20.377 13035-13035/com.example.alphabetsforkids E/MediaPlayerNative: start called in state 0, mPlayer(0x0)
2019-07-28 22:14:23.544 13035-13035/com.example.alphabetsforkids E/MediaPlayerNative: start called in state 0, mPlayer(0x0)
2019-07-28 22:14:23.553 13035-13035/com.example.alphabetsforkids E/time is greater than best time:  ----
2019-07-28 22:14:25.509 13035-13035/com.example.alphabetsforkids E/OnPause is executed--------------------: <----------
2019-07-28 22:14:25.521 13035-13035/com.example.alphabetsforkids E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.alphabetsforkids, PID: 13035
    java.lang.RuntimeException: Unable to pause activity {com.example.alphabetsforkids/com.example.alphabetsforkids.AlphabetGame}: java.lang.IllegalStateException
        at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:4306)
        at android.app.ActivityThread.performPauseActivity(ActivityThread.java:4257)
        at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:4209)
        at android.app.servertransaction.PauseActivityItem.execute(PauseActivityItem.java:46)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1935)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7116)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925)
     Caused by: java.lang.IllegalStateException
        at android.media.MediaPlayer._reset(Native Method)
        at android.media.MediaPlayer.reset(MediaPlayer.java:2145)
        at com.example.alphabetsforkids.AlphabetGame.onPause(AlphabetGame.java:365)
        at android.app.Activity.performPause(Activity.java:7874)
        at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1500)
        at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:4296)
        at android.app.ActivityThread.performPauseActivity(ActivityThread.java:4257) 
        at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:4209) 
        at android.app.servertransaction.PauseActivityItem.execute(PauseActivityItem.java:46) 
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1935) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7116) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925) 
2019-07-28 22:14:26.182 13144-13168/com.example.alphabetsforkids E/vndksupport: Could not load /vendor/lib/egl/libGLES_emulation.so from sphal namespace: dlopen failed: library "/vendor/lib/egl/libGLES_emulation.so" not found.
2019-07-28 22:14:26.182 13144-13168/com.example.alphabetsforkids E/libEGL: load_driver(/vendor/lib/egl/libGLES_emulation.so): unknown
2019-07-28 22:14:26.919 13144-13167/com.example.alphabetsforkids E/EGL_emulation: tid 13167: eglQueryString(923): error 0x3008 (EGL_BAD_DISPLAY)
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
user258959
  • 91
  • 6

2 Answers2

0

Have you tried your app on an actual device rather than an emulator? I notice your GLES library is failing to load, I'm not 100% for your situation but GLES often does not work on emulators properly.

vasmos
  • 2,472
  • 1
  • 10
  • 21
0

After plowing all the internet, I found something similar to my app and implementing it on my code, and now it works perfectly. However, I still can't run it on a real device since updating Android Studio. Need to look at that now. BTW, below is my solution to my own problem. Hope this helps others who are using AlertDialog and Media player and facing the same issue.

@Override
    protected void onPause() {
        super.onPause();
        Log.wtf("OnPause is executed--------------------", "<----------");
        if(mBackground != null){
            //mBackground.stop();  <<<----This was also in the code that I found online, but it was causing error for me so I after commenting, it worked.
            mBackground.release();
            mBackground = null;
        }
        if(mCorrect != null){
            //mCorrect.stop();
            mCorrect.release();
            mCorrect = null;
        }
        if(mWrong != null){
            //mWrong.stop();
            mWrong.release();
            mWrong = null;
        }
    }
    @Override
    protected void onResume() {
        super.onResume();

            Log.wtf("OnResume is executed--------------------", "<----------");
            if (mBackground == null || !mBackground.isPlaying()){ 
                Log.wtf("on resume---", "<---player null or not playing");
                mBackground = MediaPlayer.create(AlphabetGame.this, R.raw.mursal_bensound_littleidea);
            }
            if (mBackground.isPlaying()){
                Log.wtf("on resume---", "<---- player playing");
                mBackground.stop();
                mBackground.release();
                mBackground = MediaPlayer.create(AlphabetGame.this, R.raw.mursal_bensound_littleidea);
            }
            if (mCorrect == null || !mCorrect.isPlaying()){
                Log.wtf("on resume---", "<---player null or not playing");
                mCorrect = MediaPlayer.create(AlphabetGame.this, R.raw.correct_choice);
            }
            if (mCorrect.isPlaying()){ 
                Log.wtf("on resume---", "<---- player playing");
                mCorrect.stop();
                mCorrect.release();
                mCorrect = MediaPlayer.create(AlphabetGame.this, R.raw.correct_choice);
            }
            if (mWrong == null || !mWrong.isPlaying()){
                Log.wtf("on resume---", "<---player null or not playing");
                mWrong = MediaPlayer.create(AlphabetGame.this, R.raw.wrong_choice);
            }
            if (mWrong.isPlaying()){
                Log.wtf("on resume---", "<---- player playing");
                mWrong.stop();
                mWrong.release();
                mWrong = MediaPlayer.create(AlphabetGame.this, R.raw.wrong_choice);
            }
            mBackground.start();
            mCorrect.start();
            mWrong.start();

    }```
user258959
  • 91
  • 6