diff --git a/include/IrrlichtDevice.h b/include/IrrlichtDevice.h index c6d52985..048bc94b 100644 --- a/include/IrrlichtDevice.h +++ b/include/IrrlichtDevice.h @@ -178,7 +178,10 @@ namespace irr virtual bool isFullscreen() const = 0; //! Checks if the window could possibly be visible. - //! Currently, this only returns false when the app is paused on Android. + //! Currently, this only returns false when the activity is stopped on + //! Android. Note that for Android activities, "stopped" means something + //! different than you might expect (and also something different than + //! "paused"). Read the Android lifecycle documentation. virtual bool isWindowVisible() const { return true; }; //! Get the current color format of the window diff --git a/source/Irrlicht/Android/CIrrDeviceAndroid.cpp b/source/Irrlicht/Android/CIrrDeviceAndroid.cpp index 4ad37735..52cc95d7 100644 --- a/source/Irrlicht/Android/CIrrDeviceAndroid.cpp +++ b/source/Irrlicht/Android/CIrrDeviceAndroid.cpp @@ -31,7 +31,8 @@ namespace irr { CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param) - : CIrrDeviceStub(param), Accelerometer(0), Gyroscope(0), Focused(false), Initialized(false), Paused(true), JNIEnvAttachedToVM(0) + : CIrrDeviceStub(param), Accelerometer(0), Gyroscope(0), Initialized(false), + Stopped(true), Paused(true), Focused(false), JNIEnvAttachedToVM(0) { #ifdef _DEBUG setDebugName("CIrrDeviceAndroid"); @@ -64,7 +65,7 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param) s32 Events = 0; android_poll_source* Source = 0; - while ((ALooper_pollAll(((Focused && !Paused) || !Initialized) ? 0 : -1, 0, &Events, (void**)&Source)) >= 0) + while ((ALooper_pollAll((!Initialized || isWindowActive()) ? 0 : -1, 0, &Events, (void**)&Source)) >= 0) { if(Source) Source->process(Android, Source); @@ -180,7 +181,7 @@ void CIrrDeviceAndroid::setWindowCaption(const wchar_t* text) bool CIrrDeviceAndroid::isWindowActive() const { - return (Focused && !Paused); + return (Focused && !Paused && !Stopped); } bool CIrrDeviceAndroid::isWindowFocused() const @@ -195,7 +196,7 @@ bool CIrrDeviceAndroid::isWindowMinimized() const bool CIrrDeviceAndroid::isWindowVisible() const { - return !Paused; + return !Stopped; } void CIrrDeviceAndroid::closeDevice() @@ -265,6 +266,7 @@ void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd) break; case APP_CMD_START: os::Printer::log("Android command APP_CMD_START", ELL_DEBUG); + device->Stopped = false; break; case APP_CMD_INIT_WINDOW: os::Printer::log("Android command APP_CMD_INIT_WINDOW", ELL_DEBUG); @@ -322,6 +324,7 @@ void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd) break; case APP_CMD_STOP: os::Printer::log("Android command APP_CMD_STOP", ELL_DEBUG); + device->Stopped = true; break; case APP_CMD_RESUME: os::Printer::log("Android command APP_CMD_RESUME", ELL_DEBUG); diff --git a/source/Irrlicht/Android/CIrrDeviceAndroid.h b/source/Irrlicht/Android/CIrrDeviceAndroid.h index e7710824..9192cf13 100644 --- a/source/Irrlicht/Android/CIrrDeviceAndroid.h +++ b/source/Irrlicht/Android/CIrrDeviceAndroid.h @@ -86,9 +86,10 @@ namespace irr const ASensor* Accelerometer; const ASensor* Gyroscope; - bool Focused; bool Initialized; + bool Stopped; bool Paused; + bool Focused; JNIEnv* JNIEnvAttachedToVM;