Android onResume not called

I am developing an Android application and I want it to pause music when you press the home button (onPause). This works well, but then when I try to start the game again, onResume, onRestart, onStart, onRestoreInstanceState and onCreate are never called, and this tells me that the application is not responding. LogCat has no exceptions. Therefore, I have no idea what is happening. Does anyone have any suggestions as to why this might be so?

-EDIT- I get this error in LogCat when the application pauses:

04-16 20: 09: 32.659: ERROR / ActivityManager (66): Reason: broadcast intent {act = android.intent.action.CLOSE_SYSTEM_DIALOGS cmp = com.android.settings / .widget.SettingsAppWidgetProvider (has additional functions)}

my onPause () code is:

    public void onPause() {
    super.onPause();            
    panel.mediaPlayer.pause();
    panel.thread.running=false;
}

The main thread of the application:

        public void run() {
        running = true;
        while(running) {
            //new Canvas.
            Canvas c = null;
            //Update information
            update();
            //Draw everything to screen
            try {
                //Gets the canvas from the surfaceHolder.
                c = surfaceHolder.lockCanvas(null);
                synchronized(surfaceHolder) {
                    //draw to the canvas                    
                    doDraw(c);
                    try {
                        Thread.sleep(gameSpeed);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            } finally {
                if (c != null) {
                    surfaceHolder.unlockCanvasAndPost(c);
                }
            }
        }

mediaPlayer:

            mediaPlayer = new MediaPlayer();
    sublime = context.getResources().openRawResourceFd(R.raw.sublime);

    try {
        mediaPlayer.setLooping(true);
        mediaPlayer.setDataSource(sublime.getFileDescriptor(), sublime.getStartOffset(), sublime.getLength());
        mediaPlayer.prepare();

    } catch (IllegalArgumentException e1) {

    } catch (IllegalStateException e1) {

    } catch (IOException e1) {

    } 
    mediaPlayer.start();
0
source share
2 answers

When you receive the error message "the application is not responding", this means that your activity has been too long in the main thread of the application. Define all the work you do in the main thread of the application, and transfer the slow stuff to the background thread or AsyncTask.

+1
source

, , : , onSizeChanged SurfaceView (, , , - ) . !

0

Source: https://habr.com/ru/post/1535375/


All Articles