Reputation: 25864
I'm trying to correctly play with OpenGL in my application and having a few problems when it comes to using the Lifecycle Methods: onPause()
and onResume()
.
The documentation states:
Activity Life-cycle
A GLSurfaceView must be notified when the activity is paused and resumed. GLSurfaceView clients are required to call onPause() when the activity pauses and onResume() when the activity resumes. These calls allow GLSurfaceView to pause and resume the rendering thread, and also allow GLSurfaceView to release and recreate the OpenGL display.
First of all I was slightly confused as onPause()
and onResume()
are, throughout the rest of Android, Lifecycle events as called by the System (Activity/Fragments). Here, from the description (including the detailed descriptions in onPause() and in onResume()) it seems that they have to be called manually by the developer.
I've been using GLSurfaceView
without calling onPause()
and onResume()
and haven't noticed a problem. However, in the interests of playing ball (and decreasing likely suspects for strange behaviour on resuming the Activity) I'm trying to add them in as described in the documentation.
It seems however that using onResume() causes a NullPointerException
to be thrown:
07-23 13:20:08.570: E/AndroidRuntime(20777): Caused by: java.lang.NullPointerException
07-23 13:20:08.570: E/AndroidRuntime(20777): at android.opengl.GLSurfaceView.onResume(GLSurfaceView.java:544)
07-23 13:20:08.570: E/AndroidRuntime(20777): at com.ActivityNameHere.onResume(ActivityNameHere.java:151)
Is there a step I'm missing to register the Activity
with the View
?
Upvotes: 6
Views: 5533
Reputation: 25864
onPause()
and onResume()
are still breaking my implementation - but to be fair they're no longer doing it with a crash:
The following GLSurfaceView methods can only be called after setRenderer is called: getRenderMode() onPause() onResume() queueEvent(Runnable) requestRender() setRenderMode(int)
I was not calling setRenderer()
before my Activity.onResume()
in some instances.
Upvotes: 6