简体   繁体   English

何时调用GLSurfaceView方法onPause()和onResume()

[英]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.

相关问题 GLSurfaceView生命周期方法onPause()和onResume() - GLSurfaceView lifecycle methods onPause() and onResume() GLSurfaceView:我需要调用onPause / onResume吗? - GLSurfaceView: Do I need to to call onPause/onResume? 如何处理GLSurfaceView的onPause / onResume - How to handle onPause / onResume for GLSurfaceView Android - 如何正确处理onPause / onResume方法? - Android — How to properly handle onPause/onResume methods? 为什么要在onResume中调用startLocationUpdates并在onPause中调用stopLocationUpdates? - Why to call startLocationUpdates in onResume and stopLocationUpdates in onPause? 在GLSurfaceView上调用onResume时GLThread无法启动 - GLThread not starting when calling onResume on GLSurfaceView 当设备处于睡眠模式时,onResume 和 onPause 循环? - onResume and onPause loop when device in sleepmode? Android 游戏 - 如果游戏在 GLSurfaceView 的视频线程中运行,如何正确处理 onPause 和 onResume - Android Game - how correctly handle onPause and onResume if game runs in GLSurfaceView's video thread 连结6 fw 5.0之前的FPS低,直到调用GLSurfaceView暂停 - Low FPS on nexus 6 fw 5.0 until call onPause of GLSurfaceView 如何在我的游戏中正确放置onPause()和onResume()方法 - How to properly put onPause() and onResume() methods in my game
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM