@@ -71,7 +71,7 @@ import android.hardware.SensorManager;
7171@ANDROID_JAVA_ADDITIONS@
7272
7373public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@ SensorEventListener{
74- private android.view.View current_ContentView = null;
74+ private static android.view.View current_ContentView = null;
7575 private SensorManager mSensorManager;
7676 //Variable declarations needed for modules, e.g. gps
7777 @ANDROID_JAVA_VARIABLES@
@@ -141,16 +141,15 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@
141141 }
142142 }
143143 current_ContentView = view;
144- super.setContentView(current_ContentView);
145- if (current_ContentView instanceof android.opengl.GLSurfaceView) {
146- (( android.opengl.GLSurfaceView)current_ContentView).onResume();
147- }
144+ }
145+ super.setContentView (current_ContentView);
146+ if(current_ContentView instanceof android.opengl.GLSurfaceView) {
147+ ((android.opengl.GLSurfaceView)current_ContentView).onResume();
148148 }
149149 }
150150
151151 @Override
152152 protected void onCreate(Bundle savedInstanceState) {
153- current_ContentView = null;
154153 super.onCreate(savedInstanceState);
155154 Thread.setDefaultUncaughtExceptionHandler(
156155 new Thread.UncaughtExceptionHandler() {
@@ -169,18 +168,21 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@
169168 WindowManager.LayoutParams.FLAG_FULLSCREEN);
170169 // prevent sleep
171170 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
172- mGLView = new xGLSurfaceView(this);
173- // This may better before other pieces
174- nativeInstanceInit(getApplicationContext().getPackageCodePath().toString(), getFilesDir().toString());
171+ if(mGLView==null) { // once only!
172+ mGLView = new xGLSurfaceView(this);
173+ // This may better before other pieces
174+ nativeInstanceInit(getApplicationContext().getPackageCodePath().toString(), getFilesDir().toString());
175+ }
175176
176177 mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
177178
178179 checkOrRequestPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
179180 // Additions and permissions needed by modules, e.g. gps
180181 @ANDROID_JAVA_ONCREATE@
181182
182- setContentView(mGLView); // MUST NOT run before nativeInstanceInit completed
183-
183+ // MUST NOT run before nativeInstanceInit completed
184+ // and MUST NOT run before permission checks
185+ setContentView(current_ContentView==null ? mGLView : current_ContentView);
184186 // start EVENT_IDLE
185187 if(idle_tmScheduleRate > 0) idle_tm.scheduleAtFixedRate(idle_task, 0, idle_tmScheduleRate);
186188 }
@@ -192,23 +194,28 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@
192194 nativeEvent(127,0,0); // EVENT_TERMINATE
193195 super.onDestroy();
194196 }
197+ private void onPauseOrStop() {
198+ // Additions needed by modules, e.g. gps
199+ @ANDROID_JAVA_ONPAUSE@
200+ if (!isFinishing() && current_ContentView==mGLView && mGLView!=null) {
201+ mGLView.onPause();
202+ }
203+ }
195204 @Override
196205 protected void onStop() {
206+ Log.e("@SYS_PACKAGE_DOT@", "onStop");
207+ onPauseOrStop();
197208 super.onStop();
198209 }
199210 @Override
200211 protected void onPause() {
201- // Additions needed by modules, e.g. gps
202- @ANDROID_JAVA_ONPAUSE@
203- if (!isFinishing() && current_ContentView==mGLView) {
204- mGLView.onPause();
205- }
212+ onPauseOrStop();
206213 super.onPause();
207214 }
208215 @Override
209216 protected void onResume() {
210217 super.onResume();
211- if(current_ContentView==mGLView) {
218+ if(current_ContentView==mGLView && mGLView!=null ) {
212219 mGLView.onResume();
213220 }
214221 // Additions needed by modules, e.g. gps
@@ -232,7 +239,7 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@
232239 @ANDROID_JAVA_ACTIVITYADDITIONS@
233240
234241 // Native event bindings
235- GLSurfaceView mGLView;
242+ static GLSurfaceView mGLView = null ;
236243 native void nativeEvent(int t, int x, int y);
237244 static { System.loadLibrary("payloadshared"); }
238245 // OpenURL code
@@ -259,6 +266,7 @@ class xGLSurfaceView extends GLSurfaceView {
259266 setRenderer(renderer);
260267 }
261268 public boolean onTouchEvent(final MotionEvent event) {
269+ super.onTouchEvent(event);
262270 t=0;
263271 x=(int)event.getX(); y=(int)event.getY();
264272 switch (event.getAction()&MotionEvent.ACTION_MASK) {
0 commit comments