zghib / jmonkeyengine

Automatically exported from code.google.com/p/jmonkeyengine
0 stars 0 forks source link

Patch for /trunk/engine/src/android/com/jme3/app/AndroidHarness.java #566

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
please move the on pause code to a separate method like this. i dont want it to 
be executed when onPause is called but instead when onStop is called. or maybe 
directly move it to the onStop method.

    @Override
    protected void onPause() {
        loseFocus();

        logger.info("onPause");
        super.onPause();
        pauseApp();

    }

  protected void pauseApp() {
    if (view != null) {
            view.onPause();
        }

        if (app != null) {
            //pause the audio
            AudioRenderer result = app.getAudioRenderer();
            if (result != null) {
                logger.log(Level.INFO, "pause: {0}", result.getClass().getSimpleName());
                if (result instanceof AndroidAudioRenderer) {
                    AndroidAudioRenderer renderer = (AndroidAudioRenderer) result;
                    renderer.pauseAll();
                }
            }
            //pause the sensors (aka joysticks)
            if (app.getContext() != null) {
                JoyInput joyInput = app.getContext().getJoyInput();
                if (joyInput != null) {
                    if (joyInput instanceof AndroidSensorJoyInput) {
                        AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput;
                        androidJoyInput.pauseSensors();
                    }
                }
            }
        }
        isGLThreadPaused = true;
  }

Original issue reported on code.google.com by simon.heinen on 3 Jan 2013 at 10:53

Attachments:

GoogleCodeExporter commented 8 years ago
I don't get the point, could you explain?

Original comment by remy.bou...@gmail.com on 13 Feb 2013 at 9:47

GoogleCodeExporter commented 8 years ago
I refactored the onPause method and extracted much of the code to a newly 
created method called pauseApp() so that the new pauseApp() method can also be 
called from other methods like the onStop method in a possible subclass of 
AndroidHarness. I think thats a better solution then just copying all the code 
in the pauseApp() method

Original comment by simon.heinen on 13 Feb 2013 at 9:52

GoogleCodeExporter commented 8 years ago
No, i mean, why would I want to call pausApp() when stopping the application?

The life cycle of the JME app is hard to manage on android so if you found 
something better, i'd like to know why, how and so on.

When reading your issue it's like "I want to call pause when i stop, so 
refactor the pause code". And this does not make much sense.

Original comment by remy.bou...@gmail.com on 13 Feb 2013 at 10:02

GoogleCodeExporter commented 8 years ago
Ok I often use other transparent activities in the forground of the 
AndroidHarness activity so I basicly do the stuff you do in onPause in onStop. 
This allows to continue running the game and the rendering when the other 
activity is in the foreground. I think its ok do normally do the on pause stuff 
in onPause but for transparent windows it looks much nicer if the rendering and 
animations continue when the other activity is in the foreground. for non 
transparent activities in the foreground it makes sense to use the normal on 
pause behaviour to free ressources but for this scenario it would be nice to 
refactor the onPause method how i suggested (or in a similar way) 

Original comment by simon.heinen on 13 Feb 2013 at 10:14

GoogleCodeExporter commented 8 years ago
The app pause/resume code has been moved to the loseFocus/gainFocus public 
methods in AndroidHarness.  If you want to change when the app stops/resumes 
override onPause/onResume and remove the call to loseFocus/gainFocus.  You can 
then call these methods in some other method (like onStop/onStart).

Original comment by iwgeric on 11 May 2013 at 4:12

GoogleCodeExporter commented 8 years ago

Original comment by iwgeric on 11 May 2013 at 4:15