Re: [android-developers] Re: Detect/intercept screen turning off
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dianne Hackborn wrote: Also you definitely do get paused when the screen is turning off, so you really should be able to fix things by doing whatever you need to there. What I'm trying to do is to work around bug 3755: http://code.google.com/p/android/issues/detail?id=3755 OpenGL apps don't get notified of surface destruction when the screen turns off, which means they try to render onto an invalid surface, which means the GL system gets itself knotted up and shifts into a state where it won't work any more. We do get onPause() when the screen turns off, but unfortunately it's sometimes too late (there appears to be a race between surface destruction and the onPause() being delivered). It just so happens that with apps using GLSurfaceView this mostly works, and with our app (which doesn't use GLSurfaceView) it mostly doesn't work! Testing for ACTION_SCREEN_OFF is a reasonable workaround --- it allows me to distinguish between the application being paused because it's being backgrounded (which works correctly) and the application being paused because the screen's being turned off (which doesn't); but because it's arriving after the onPause(), it's still arriving after surface destruction, which means it's too late to save the app, so all I can really do is quit. But that's way better than crashing --- thanks! (What I'd really like to do is to be able to detect the screen turning off *before* it actually does so, so I can switch to a different activity and therefore artifically force a paused-due-to-backgrounding event. Unfortunately I don't think any such event gets delivered.) - -- ┌─── dg@cowlark.com ─ http://www.cowlark.com ─ │ │ Under communism, man exploits man. Under capitalism, it's just the │ opposite. --- John Kenneth Galbrith -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iD8DBQFLEl8rf9E0noFvlzgRAlPRAKCjegDGvhGmko4osetZnWvMddp0mwCgnKNX a8v790x7bO1nr/utrZRnFHY= =Y/He -END PGP SIGNATURE- -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Detect/intercept screen turning off
I wouldn't count on the screen off broadcast being delivered at some useful different timing from onPause(). These are both part of the flow of turning off the screen, they will happen pretty much at the same time. On Sun, Nov 29, 2009 at 3:46 AM, David Given d...@cowlark.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dianne Hackborn wrote: Also you definitely do get paused when the screen is turning off, so you really should be able to fix things by doing whatever you need to there. What I'm trying to do is to work around bug 3755: http://code.google.com/p/android/issues/detail?id=3755 OpenGL apps don't get notified of surface destruction when the screen turns off, which means they try to render onto an invalid surface, which means the GL system gets itself knotted up and shifts into a state where it won't work any more. We do get onPause() when the screen turns off, but unfortunately it's sometimes too late (there appears to be a race between surface destruction and the onPause() being delivered). It just so happens that with apps using GLSurfaceView this mostly works, and with our app (which doesn't use GLSurfaceView) it mostly doesn't work! Testing for ACTION_SCREEN_OFF is a reasonable workaround --- it allows me to distinguish between the application being paused because it's being backgrounded (which works correctly) and the application being paused because the screen's being turned off (which doesn't); but because it's arriving after the onPause(), it's still arriving after surface destruction, which means it's too late to save the app, so all I can really do is quit. But that's way better than crashing --- thanks! (What I'd really like to do is to be able to detect the screen turning off *before* it actually does so, so I can switch to a different activity and therefore artifically force a paused-due-to-backgrounding event. Unfortunately I don't think any such event gets delivered.) - -- ┌─── dg@cowlark.com ─ http://www.cowlark.com ─ │ │ Under communism, man exploits man. Under capitalism, it's just the │ opposite. --- John Kenneth Galbrith -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iD8DBQFLEl8rf9E0noFvlzgRAlPRAKCjegDGvhGmko4osetZnWvMddp0mwCgnKNX a8v790x7bO1nr/utrZRnFHY= =Y/He -END PGP SIGNATURE- -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Detect/intercept screen turning off
Im not sure you can catch it from turning off, but you can setup a broadcast receiver to let you know when that happens. Your receiver must be defined in java (not xml) and look for the ACTION_SCREEN_OFF broadcast. Hope that helps, theSmith On Nov 27, 6:47 am, David Given d...@cowlark.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Is there any way where I can detect that the screen is about to turn off, so I can do some work *before* it happens? I need this to work around bug 3755: OpenGL apps sometimes crash when the screen gets turned off because they don't get surfaceDestroyed()/surfaceCreated() events. http://code.google.com/p/android/issues/detail?id=3755 Simply put, I need to shut down OpenGL before the phone has a chance to detach the GPU. The only events I seems to be getting when the screen turns off are onPause() and onWindowFocusChanged()... both of which turn up *after* the GPU detaches, by which time it's too late. Can anyone suggest any way of doing this? (In desperation, I have tried to intercept the power key, but the power/hangup key is treated specially and doesn't generate keyboard events...) - -- ┌─── dg@cowlark.com ─http://www.cowlark.com─ │ │ Sufficiently advanced incompetence is indistinguishable from │ malice. -- Vernon Schryver -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org iEYEARECAAYFAksPvFIACgkQf9E0noFvlzioGACfW5r72xNXqykHvSu4SocKo0bw rlkAoLNa6NZiWgczIBHtLmgJmzFZLiaR =HOwY -END PGP SIGNATURE- -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Detect/intercept screen turning off
Also you definitely do get paused when the screen is turning off, so you really should be able to fix things by doing whatever you need to there. On Fri, Nov 27, 2009 at 10:11 AM, theSmith chris.smith...@gmail.com wrote: Im not sure you can catch it from turning off, but you can setup a broadcast receiver to let you know when that happens. Your receiver must be defined in java (not xml) and look for the ACTION_SCREEN_OFF broadcast. Hope that helps, theSmith On Nov 27, 6:47 am, David Given d...@cowlark.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Is there any way where I can detect that the screen is about to turn off, so I can do some work *before* it happens? I need this to work around bug 3755: OpenGL apps sometimes crash when the screen gets turned off because they don't get surfaceDestroyed()/surfaceCreated() events. http://code.google.com/p/android/issues/detail?id=3755 Simply put, I need to shut down OpenGL before the phone has a chance to detach the GPU. The only events I seems to be getting when the screen turns off are onPause() and onWindowFocusChanged()... both of which turn up *after* the GPU detaches, by which time it's too late. Can anyone suggest any way of doing this? (In desperation, I have tried to intercept the power key, but the power/hangup key is treated specially and doesn't generate keyboard events...) - -- ┌─── dg@cowlark.com ─http://www.cowlark.com─ │ │ Sufficiently advanced incompetence is indistinguishable from │ malice. -- Vernon Schryver -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org iEYEARECAAYFAksPvFIACgkQf9E0noFvlzioGACfW5r72xNXqykHvSu4SocKo0bw rlkAoLNa6NZiWgczIBHtLmgJmzFZLiaR =HOwY -END PGP SIGNATURE- -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Detect/intercept screen turning off
Hi, just came across this thread http://www.mail-archive.com/android-developers@googlegroups.com/msg63994.html. Hope this might help you. Also, does the use of android.os.PowerManager.WakeLock class feasible for your apps? On Nov 27, 3:47 am, David Given d...@cowlark.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Is there any way where I can detect that the screen is about to turn off, so I can do some work *before* it happens? I need this to work around bug 3755: OpenGL apps sometimes crash when the screen gets turned off because they don't get surfaceDestroyed()/surfaceCreated() events. http://code.google.com/p/android/issues/detail?id=3755 Simply put, I need to shut down OpenGL before the phone has a chance to detach the GPU. The only events I seems to be getting when the screen turns off are onPause() and onWindowFocusChanged()... both of which turn up *after* the GPU detaches, by which time it's too late. Can anyone suggest any way of doing this? (In desperation, I have tried to intercept the power key, but the power/hangup key is treated specially and doesn't generate keyboard events...) - -- ┌─── dg@cowlark.com ─http://www.cowlark.com─ │ │ Sufficiently advanced incompetence is indistinguishable from │ malice. -- Vernon Schryver -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org iEYEARECAAYFAksPvFIACgkQf9E0noFvlzioGACfW5r72xNXqykHvSu4SocKo0bw rlkAoLNa6NZiWgczIBHtLmgJmzFZLiaR =HOwY -END PGP SIGNATURE- -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en