SDL Android back button bug

In our android game we use SDLK_AC_BACK to implement custom behavior when
user presses back button. We also use in-app purchases. When you initiate
in-app purchase system dialog appears. After completion/canceling it
pressing back button no longer triggers SDLK_AC_BACK key events and
switches to default behavior - finishing current activity. After some
investigation I figured our that this happens because of onPause() ->
onResume() cycle for main activity. SDLSurface is not assigned to handle
key presses in onResume(). Note that when you minimize app it goes through
full onPause() -> onStop() -> onStart() -> onResume() cycle and SDLSurface
is recreated, reassigned to handle keys in it’s constructor and everything
works well. So in our case we quickfixed this bug with something like this:

— a/SDLActivity.java
+++ b/SDLActivity.java
@@ -198,6 +198,7 @@ public class SDLActivity extends Activity {
if (SDLActivity.mIsPaused && SDLActivity.mIsSurfaceReady &&
SDLActivity.mHasFocus) {
SDLActivity.mIsPaused = false;
SDLActivity.nativeResume();

  •        mSurface.handleResume();
           mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
       }
    

    }
    @@ -499,6 +500,14 @@ class SDLSurface extends SurfaceView implements
    SurfaceHolder.Callback,
    mWidth = 1.0f;
    mHeight = 1.0f;
    }+

  • public void handleResume() {

  •    setFocusable(true);
    
  •    setFocusableInTouchMode(true);
    
  •    requestFocus();
    
  •    setOnKeyListener(this);
    
  •    setOnTouchListener(this);
    
  • }

    public Surface getNativeSurface() {
    return getHolder().getSurface();

But i’m sure it’s a good fix and probably it should be rewritten with
someone who knowns SDLActivity structure better than me :wink:

Thanks, I’ll review this ASAP.

2014-03-26 12:55 GMT-03:00 Alexey Petruchik <alexey.petruchik at gmail.com>:> In our android game we use SDLK_AC_BACK to implement custom behavior when

user presses back button. We also use in-app purchases. When you initiate
in-app purchase system dialog appears. After completion/canceling it
pressing back button no longer triggers SDLK_AC_BACK key events and
switches to default behavior - finishing current activity. After some
investigation I figured our that this happens because of onPause() ->
onResume() cycle for main activity. SDLSurface is not assigned to handle
key presses in onResume(). Note that when you minimize app it goes through
full onPause() -> onStop() -> onStart() -> onResume() cycle and SDLSurface
is recreated, reassigned to handle keys in it’s constructor and everything
works well. So in our case we quickfixed this bug with something like this:

— a/SDLActivity.java
+++ b/SDLActivity.java
@@ -198,6 +198,7 @@ public class SDLActivity extends Activity {
if (SDLActivity.mIsPaused && SDLActivity.mIsSurfaceReady &&
SDLActivity.mHasFocus) {
SDLActivity.mIsPaused = false;
SDLActivity.nativeResume();

  •        mSurface.handleResume();
           mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
       }
    

    }
    @@ -499,6 +500,14 @@ class SDLSurface extends SurfaceView implements
    SurfaceHolder.Callback,
    mWidth = 1.0f;
    mHeight = 1.0f;
    }

  • public void handleResume() {

  •    setFocusable(true);
    
  •    setFocusableInTouchMode(true);
    
  •    requestFocus();
    
  •    setOnKeyListener(this);
    
  •    setOnTouchListener(this);
    
  • }

    public Surface getNativeSurface() {
    return getHolder().getSurface();

But i’m sure it’s a good fix and probably it should be rewritten with
someone who knowns SDLActivity structure better than me :wink:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.

Hi, any update on this one?On Wed, Mar 26, 2014 at 7:25 PM, Gabriel Jacobo wrote:

Thanks, I’ll review this ASAP.

2014-03-26 12:55 GMT-03:00 Alexey Petruchik <@Alexey_Petruchik>:

In our android game we use SDLK_AC_BACK to implement custom behavior when
user presses back button. We also use in-app purchases. When you initiate
in-app purchase system dialog appears. After completion/canceling it
pressing back button no longer triggers SDLK_AC_BACK key events and
switches to default behavior - finishing current activity. After some
investigation I figured our that this happens because of onPause() ->
onResume() cycle for main activity. SDLSurface is not assigned to handle
key presses in onResume(). Note that when you minimize app it goes through
full onPause() -> onStop() -> onStart() -> onResume() cycle and SDLSurface
is recreated, reassigned to handle keys in it’s constructor and everything
works well. So in our case we quickfixed this bug with something like this:

— a/SDLActivity.java
+++ b/SDLActivity.java
@@ -198,6 +198,7 @@ public class SDLActivity extends Activity {
if (SDLActivity.mIsPaused && SDLActivity.mIsSurfaceReady &&
SDLActivity.mHasFocus) {
SDLActivity.mIsPaused = false;
SDLActivity.nativeResume();

  •        mSurface.handleResume();
           mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
       }
    

    }
    @@ -499,6 +500,14 @@ class SDLSurface extends SurfaceView implements
    SurfaceHolder.Callback,
    mWidth = 1.0f;
    mHeight = 1.0f;
    }

  • public void handleResume() {

  •    setFocusable(true);
    
  •    setFocusableInTouchMode(true);
    
  •    requestFocus();
    
  •    setOnKeyListener(this);
    
  •    setOnTouchListener(this);
    
  • }

    public Surface getNativeSurface() {
    return getHolder().getSurface();

But i’m sure it’s a good fix and probably it should be rewritten with
someone who knowns SDLActivity structure better than me :wink:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Sorry for the delay! https://hg.libsdl.org/SDL/rev/a9520d7a579c

2014-05-01 11:09 GMT-03:00 Alexey Petruchik <alexey.petruchik at gmail.com>:> Hi, any update on this one?

On Wed, Mar 26, 2014 at 7:25 PM, Gabriel Jacobo <@Gabriel_Jacobo> wrote:

Thanks, I’ll review this ASAP.

2014-03-26 12:55 GMT-03:00 Alexey Petruchik <alexey.petruchik at gmail.com>:

In our android game we use SDLK_AC_BACK to implement custom behavior
when user presses back button. We also use in-app purchases. When you
initiate in-app purchase system dialog appears. After completion/canceling
it pressing back button no longer triggers SDLK_AC_BACK key events and
switches to default behavior - finishing current activity. After some
investigation I figured our that this happens because of onPause() ->
onResume() cycle for main activity. SDLSurface is not assigned to handle
key presses in onResume(). Note that when you minimize app it goes through
full onPause() -> onStop() -> onStart() -> onResume() cycle and SDLSurface
is recreated, reassigned to handle keys in it’s constructor and everything
works well. So in our case we quickfixed this bug with something like this:

— a/SDLActivity.java
+++ b/SDLActivity.java
@@ -198,6 +198,7 @@ public class SDLActivity extends Activity {
if (SDLActivity.mIsPaused && SDLActivity.mIsSurfaceReady &&
SDLActivity.mHasFocus) {
SDLActivity.mIsPaused = false;
SDLActivity.nativeResume();

  •        mSurface.handleResume();
           mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
       }
    

    }
    @@ -499,6 +500,14 @@ class SDLSurface extends SurfaceView implements
    SurfaceHolder.Callback,
    mWidth = 1.0f;
    mHeight = 1.0f;
    }

  • public void handleResume() {

  •    setFocusable(true);
    
  •    setFocusableInTouchMode(true);
    
  •    requestFocus();
    
  •    setOnKeyListener(this);
    
  •    setOnTouchListener(this);
    
  • }

    public Surface getNativeSurface() {
    return getHolder().getSurface();

But i’m sure it’s a good fix and probably it should be rewritten with
someone who knowns SDLActivity structure better than me :wink:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.

Oh, you just applied my dirty hack as is. Now we have some code duplication
in SDLSurface constructor and handleResume method.On Sun, May 11, 2014 at 12:38 AM, Gabriel Jacobo wrote:

Sorry for the delay! https://hg.libsdl.org/SDL/rev/a9520d7a579c

2014-05-01 11:09 GMT-03:00 Alexey Petruchik <@Alexey_Petruchik>:

Hi, any update on this one?

On Wed, Mar 26, 2014 at 7:25 PM, Gabriel Jacobo wrote:

Thanks, I’ll review this ASAP.

2014-03-26 12:55 GMT-03:00 Alexey Petruchik <@Alexey_Petruchik>
:

In our android game we use SDLK_AC_BACK to implement custom behavior
when user presses back button. We also use in-app purchases. When you
initiate in-app purchase system dialog appears. After completion/canceling
it pressing back button no longer triggers SDLK_AC_BACK key events and
switches to default behavior - finishing current activity. After some
investigation I figured our that this happens because of onPause() ->
onResume() cycle for main activity. SDLSurface is not assigned to handle
key presses in onResume(). Note that when you minimize app it goes through
full onPause() -> onStop() -> onStart() -> onResume() cycle and SDLSurface
is recreated, reassigned to handle keys in it’s constructor and everything
works well. So in our case we quickfixed this bug with something like this:

— a/SDLActivity.java
+++ b/SDLActivity.java
@@ -198,6 +198,7 @@ public class SDLActivity extends Activity {
if (SDLActivity.mIsPaused && SDLActivity.mIsSurfaceReady &&
SDLActivity.mHasFocus) {
SDLActivity.mIsPaused = false;
SDLActivity.nativeResume();

  •        mSurface.handleResume();
           mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
       }
    

    }
    @@ -499,6 +500,14 @@ class SDLSurface extends SurfaceView implements
    SurfaceHolder.Callback,
    mWidth = 1.0f;
    mHeight = 1.0f;
    }

  • public void handleResume() {

  •    setFocusable(true);
    
  •    setFocusableInTouchMode(true);
    
  •    requestFocus();
    
  •    setOnKeyListener(this);
    
  •    setOnTouchListener(this);
    
  • }

    public Surface getNativeSurface() {
    return getHolder().getSurface();

But i’m sure it’s a good fix and probably it should be rewritten with
someone who knowns SDLActivity structure better than me :wink:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Btw, Gabriel, could you also look at this one
https://bugzilla.libsdl.org/show_bug.cgi?id=2498. This patch seems to be no
so dirty ;)On Sun, May 11, 2014 at 5:01 AM, Alexey Petruchik < @Alexey_Petruchik> wrote:

Oh, you just applied my dirty hack as is. Now we have some code
duplication in SDLSurface constructor and handleResume method.

On Sun, May 11, 2014 at 12:38 AM, Gabriel Jacobo wrote:

Sorry for the delay! https://hg.libsdl.org/SDL/rev/a9520d7a579c

2014-05-01 11:09 GMT-03:00 Alexey Petruchik <@Alexey_Petruchik>:

Hi, any update on this one?

On Wed, Mar 26, 2014 at 7:25 PM, Gabriel Jacobo wrote:

Thanks, I’ll review this ASAP.

2014-03-26 12:55 GMT-03:00 Alexey Petruchik <@Alexey_Petruchik

:

In our android game we use SDLK_AC_BACK to implement custom behavior
when user presses back button. We also use in-app purchases. When you
initiate in-app purchase system dialog appears. After completion/canceling
it pressing back button no longer triggers SDLK_AC_BACK key events and
switches to default behavior - finishing current activity. After some
investigation I figured our that this happens because of onPause() ->
onResume() cycle for main activity. SDLSurface is not assigned to handle
key presses in onResume(). Note that when you minimize app it goes through
full onPause() -> onStop() -> onStart() -> onResume() cycle and SDLSurface
is recreated, reassigned to handle keys in it’s constructor and everything
works well. So in our case we quickfixed this bug with something like this:

— a/SDLActivity.java
+++ b/SDLActivity.java
@@ -198,6 +198,7 @@ public class SDLActivity extends Activity {
if (SDLActivity.mIsPaused && SDLActivity.mIsSurfaceReady &&
SDLActivity.mHasFocus) {
SDLActivity.mIsPaused = false;
SDLActivity.nativeResume();

  •        mSurface.handleResume();
           mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
       }
    

    }
    @@ -499,6 +500,14 @@ class SDLSurface extends SurfaceView implements
    SurfaceHolder.Callback,
    mWidth = 1.0f;
    mHeight = 1.0f;
    }

  • public void handleResume() {

  •    setFocusable(true);
    
  •    setFocusableInTouchMode(true);
    
  •    requestFocus();
    
  •    setOnKeyListener(this);
    
  •    setOnTouchListener(this);
    
  • }

    public Surface getNativeSurface() {
    return getHolder().getSurface();

But i’m sure it’s a good fix and probably it should be rewritten with
someone who knowns SDLActivity structure better than me :wink:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org