我需要从NativeActivity禁用/启用屏幕调暗(当由OpenGL执行渲染时)。我继承了MyNativeActivity:
public class MyNativeActivity extends NativeActivity {
public final void disableAutoSleep()
{
Log.d("TWP", "disableAutoSleep()...");
runOnUiThread(new Runnable() {
@Override
public void run()
{
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
});
}
}
然后我使用JNI从我的本机代码中调用此方法。我在LogCat中看到的是:
06-03 16:51:26.964: D/TWP(2531): disableAutoSleep()...
06-03 16:51:27.034: E/BufferQueue(125): [com.example.MyNativeActivity]
dequeueBuffer: SurfaceTexture has been abandoned!
06-03 16:51:27.034: W/nvwsi(2531): dequeueBuffer failed, error -19
然后glGetError()
(在我的渲染例程中)返回GL_INVALID_FRAMEBUFFER_OPERATION
,屏幕变黑。
似乎Android终止或重新创建我的绘图窗口以响应getWindow().addFlags(...)
。但是我没有在engine_handle_cmd
中收到任何通知(这是本机活动中的主要C ++消息回调)。我该如何处理它或我做错了什么?
更新
我试过
ANativeActivity_setWindowFlags(state->activity, AWINDOW_FLAG_KEEP_SCREEN_ON, 0);
但也导致了
06-03 18:34:47.054: E/BufferQueue(125): [com.example.MyNativeActivity] dequeueBuffer: SurfaceTexture has been abandoned!