thanks a lot. my app have to fit for lots of devices even on android 2.0, for renderering 3d's buildings in my navigation's app. normally, need switch ui between multiple activities, and had to persist the correct state, so i want to reuse one GLSurfaceView, however it's too difficult to implement it, it have been troubled me for a long time. i saw your answer and very excited, but i don't know what's wrong with my code, it doesn't work.My code is shown below. first run into the one activity, it's fine.when switch to the second activity, and return to the one activity from the second activity again, the GLSurfaceView doesn't work.
======MyApplication===========================================================================================
thanks a lot. my app have to fit for lots of devices even on android 2.0, for renderering 3d's buildings in my navigation's app. normally, need switch ui between multiple activities, and had to persist the correct state, so i want to reuse one GLSurfaceView, however it's too difficult to implement it, it have been troubled me for a long time. i saw your answer and very excited, but i don't know what's wrong with my code, it doesn't work.My code is shown below. the first run into the one activity, it's fine.when switch to the second activity, and return to the one activity from the second activity again, the GLSurfaceView doesn't work.
======MyApplication===========================================================================================
//in myApplication, i create a GLSurfaceView and a Renderer.
private ClearGLSurfaceView mGLView;
private ClearRenderer mRenderer;
private LinearLayout mUnityView;
@Override
public void onCreate() {
mGLView = new ClearGLSurfaceView(this.getApplicationContext());
mRenderer = new ClearRenderer();
mGLView.setRenderer(mRenderer);
mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
mUnityView = new LinearLayout(this.getApplicationContext());
mUnityView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
mUnityView.setOrientation(LinearLayout.VERTICAL);
mUnityView.addView(mGLView);
}
======OneActivity===========================================================================================
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLViewParent = new LinearLayout(this);
mGLViewParent.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
MyApplication myApp = (MyApplication) getApplication();
mGLViewParent.setOrientation(LinearLayout.VERTICAL);
mGLView = myApp.getGLView();
mUnityView = myApp.getUnityView();
mGLViewParent.addView(mUnityView);
setContentView(mGLViewParent);
}
@Override
protected void onPause() {
super.onPause();
mGLView.setVisibility(View.INVISIBLE);
mGLViewParent.removeView(mUnityView);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus && mGLView != null && mGLView.getVisibility() == View.GONE)){
mGLViewParent.addView(mUnityView);
mGLView.setVisibility(View.VISIBLE);
}
super.onWindowFocusChanged(hasFocus);
}
//here jump to the second activity, however return to this activity from the second activity again, the GLSurfaceView doesn't work.
public boolean onTouchEvent(final MotionEvent event) {
Intent it = new Intent();
it.setClass(MainActivity.this, SecondActivity.class);
MainActivity.this.startActivity(it);
return false;
}
=========================================================================================================================
Any help will be really apreciated.
Qeeshan.
在 2013年8月18日星期日UTC+8下午9时57分38秒,Chris Pruett写道: