[英]When to call GLSurfaceView methods onPause() and onResume()
I have repeatedly read that onPause() and onResume() must be called for the GLSurfaceview during the onPause() and onResume() methods of the enclosing activity. 我反复读过,在封闭活动的onPause()和onResume()方法期间,必须为GLSurfaceview调用onPause()和onResume()。 I gather that this is to stop and restart the rendering thread to save resources.
我认为这是为了停止并重新启动渲染线程以节省资源。 However, when I log each iteration of the onDraw method of the rendering thread, I see that onDraw stops being called when I press the home or back buttons, and when I return to the app, onSurfaceCreated and onSurfaceChanged get called, and then the onDraw call resume - even after I remove the calls to the GLSurfaceview's onPause() and onResume() methods in the corresponding activity methods.
但是,当我记录渲染线程的onDraw方法的每次迭代时,我看到当按下主屏幕或后退按钮,并且当我返回到应用程序时,onDraw停止被调用,先调用onSurfaceCreated和onSurfaceChanged,然后调用onDraw呼叫恢复-即使在删除了对应活动方法中对GLSurfaceview的onPause()和onResume()方法的调用之后,也是如此。 If the rendering thread is not being stopped, how am I seeing this behavior?
如果渲染线程没有停止,我如何看到此行为? Is the rendering thread still somehow alive even though onDraw is no longer being called?
即使不再调用onDraw,渲染线程是否仍然可以存活? And if the rendering thread is being shut down automatically when the activity loses focus, then why is it necessary to call the GLSurfaceview versions of onPause() and onResume()?
并且,如果活动失去焦点时呈现线程自动关闭,那么为什么必须调用onPause()和onResume()的GLSurfaceview版本?
It seems like a bug in GLSurfaceView
where it tries to be clever by tolerating you forgetting to call onResume()
and onPause()
. 看起来像是
GLSurfaceView
中的错误,它通过容忍您忘记调用onResume()
和onPause()
来试图变得聪明。 I'm not sure if this is deliberate or not. 我不确定这是否是故意的。
Leaving the calls out works almost always, but it can cause odd behaviour and crashes in some situations. 忽略呼叫几乎总是可行的,但是在某些情况下可能导致奇怪的行为并崩溃。 I'm not exactly sure what those situations are, but I have traced a few weird crashes back to missing
onResume()
/ onPause()
calls. 我不确定这些情况是什么,但是我已经追溯到一些奇怪的崩溃,原因是缺少
onResume()
/ onPause()
调用。 Something gets slightly messed up with the state machine in GLSurfaceView
when you don't call them - it looks like the fallback logic to 'automatically' resume and pause doesn't get triggered in 100% of cases. 当您不调用状态机时,
GLSurfaceView
的状态机会有些混乱–看起来“自动”恢复和暂停的后备逻辑在100%的情况下不会触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.