I am trying to make my game multitask friendly, however whenever the screen is turned off and turned back on, or the game is navigated away from and back to, I get a null pointer exception pointing to this part of the code:
GLES20.glUniformMatrix3fv(mTextureMatrixHandle, 1, false, render.mTexMatrix, 0);
I don’t have anything apart from super.onResume(); and mGLSurfaceView.onResume(); for the onResume() method and the same for onPause(), except with onPause rather than onResume. Any idea how to fix this?
You must make sure that the objects are re-created when the activity is started again. Where are those variables initialized? Typical case for this kind error is when you store objects in a global variables. When the activity is created again, they are null.
So: check which of mTextureMatrixHandle, render, or render.mTexMatrix is null. Re-create it if it is null.
In general, you should not rely on any data being restored at activity creation. So don’t use global variables, and rely only on data passed via the intent. If you really want to use global data, you should be aware that it may be reset, and re-create it when needed.