我的應用程序有第二個包含GLSurfaceView的Activity。這顯示了第一個活動中整理的OpenGL ES 1.0圖表數據。包括方位變化在內的一切都很好。應用程序可以彈出和退出兩個活動,處理方向更改並且沒有任何問題。但是,如果我在第二個活動中顯示OpenGL圖表,然後按下Android主屏幕,然後從菜單上的應用程序列表中選擇它,然後回到應用程序,我會收到一條消息:「不幸的是, XXX已經停止。「解決Android/OpenGL IllegalStateException
在Logcat中,我看到這個:IllegalStateException: setRenderer has already been called for this instance
,我已經將它跟蹤到mGLView.setRenderer (new GLRenderer (this));
我在Activity的onStart()
方法中的代碼行。
我把日誌行立即在前面,這個電話之後......當崩潰發生,我看到的logcat以下...
02-18 09:48:08.743 1953-1953/com.hippo.happ I/HActivity? Just before the setRenderer call...
02-18 09:48:08.753 1953-1953/com.hippo.happ D/AndroidRuntime? Shutting down VM
02-18 09:48:08.753 1953-1953/com.hippo.happ W/dalvikvm? threadid=1: thread exiting with uncaught exception (group=0xb0d75b08)
02-18 09:48:08.763 1953-1953/com.hippo.happ E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.hippo.happ, PID: 1953
java.lang.RuntimeException: Unable to resume activity {com.hippo.happ/com.hippo.happ.HChartActivity}: java.lang.IllegalStateException: setRenderer has already been called for this instance.
但我沒有看到這一點,除非活動被首次創建:
02-18 09:47:51.123 1953-1953/com.hippo.happ I/HActivity? Just after the setRenderer call...
我可以證實,我不調用setEGLContextClientVersion
可言,我也沒有改變渲染模式setRenderMode
。 I 具有實施onPause()
和onResume()
。
我可以使用一些代碼來檢查「setRenderer是否已經被調用這個實例」(我看不到在文檔中適當的獲取或檢查方法),或者我可以圍繞在try..catch setRender
行阻止和扼殺IllegalStateException
?那會是推薦的方式來解決這個問題嗎?
IllegalStateException **可以被忽略 - 如果已經完成,OpenGL圖表會按預期的方式返回,它並不認爲這是做這件事的正確方法,但至少應用程序不會' t崩潰。我歡迎任何其他的建議...... – Hippogriff