Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid OpenGL ES: Resuming/pausing an Activity
    primarykey
    data
    text
    <p>I am having difficulties understanding the right way to split initialization and maintenance of application state between Activity, GLSurfaceView and Renderer. Let's say I have a game with complex objects, complex state and want to preserve the state and load it on each onResume. My initialization goes like this:</p> <pre><code>public class MyActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gamescreenView = (GLGameScreenSurface) findViewById(R.id.GLGamescreenView); ... if (savedInstanceState == null) { Game.init(); resuming = false; } else { gamedata = (GameData) savedInstanceState.getSerializable("gamedata"); resuming = true; } renderer = new MyRenderer(this, gamedata, gamescreenView, handle, resuming); gamescreenView.setRenderer(renderer); } @Override public void onPause(){ super.onPause(); gamescreenView.onPause(); gamedata = renderer.gamedata; } @Override public void onResume(){ super.onResume(); gamescreenView.onResume(); renderer.gamedata= gamedata; } @Override public void onSaveInstanceState(Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); savedInstanceState.putSerializable("gamedata", renderer.gamedata); } @Override public void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); gamedata = (UniverseHolder) savedInstanceState.getSerializable("gamedata"); } </code></pre> <p>here is my Renderer:</p> <pre><code>public class MyRenderer implements GLSurfaceView.Renderer { public WideOpenRenderer(Context context, UniverseHolder universe, GLGameScreenSurface gamescreenView, Handler handler, boolean resuming) { this.context = context; this.handler = handler; parent = gamescreenView; this.gamedata = gamedata; this.resuming = resuming; } public void onSurfaceCreated(GL10 unused, EGLConfig config) { GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); Log.d("mydebug", "" + resuming); gamedata.init(); } ... </code></pre> <p>But it does not work this way and resuming is always false according to the log.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload