@@ -71,7 +71,7 @@ import android.hardware.SensorManager;
71
71
@ANDROID_JAVA_ADDITIONS@
72
72
73
73
public 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;
75
75
private SensorManager mSensorManager;
76
76
//Variable declarations needed for modules, e.g. gps
77
77
@ANDROID_JAVA_VARIABLES@
@@ -141,16 +141,15 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@
141
141
}
142
142
}
143
143
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();
148
148
}
149
149
}
150
150
151
151
@Override
152
152
protected void onCreate(Bundle savedInstanceState) {
153
- current_ContentView = null;
154
153
super.onCreate(savedInstanceState);
155
154
Thread.setDefaultUncaughtExceptionHandler(
156
155
new Thread.UncaughtExceptionHandler() {
@@ -169,18 +168,21 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@
169
168
WindowManager.LayoutParams.FLAG_FULLSCREEN);
170
169
// prevent sleep
171
170
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
+ }
175
176
176
177
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
177
178
178
179
checkOrRequestPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
179
180
// Additions and permissions needed by modules, e.g. gps
180
181
@ANDROID_JAVA_ONCREATE@
181
182
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);
184
186
// start EVENT_IDLE
185
187
if(idle_tmScheduleRate > 0) idle_tm.scheduleAtFixedRate(idle_task, 0, idle_tmScheduleRate);
186
188
}
@@ -192,23 +194,28 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@
192
194
nativeEvent(127,0,0); // EVENT_TERMINATE
193
195
super.onDestroy();
194
196
}
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
+ }
195
204
@Override
196
205
protected void onStop() {
206
+ Log.e("@SYS_PACKAGE_DOT@", "onStop");
207
+ onPauseOrStop();
197
208
super.onStop();
198
209
}
199
210
@Override
200
211
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();
206
213
super.onPause();
207
214
}
208
215
@Override
209
216
protected void onResume() {
210
217
super.onResume();
211
- if(current_ContentView==mGLView) {
218
+ if(current_ContentView==mGLView && mGLView!=null ) {
212
219
mGLView.onResume();
213
220
}
214
221
// Additions needed by modules, e.g. gps
@@ -232,7 +239,7 @@ public class @SYS_APPNAME@ extends Activity implements @ANDROID_JAVA_IMPLEMENTS@
232
239
@ANDROID_JAVA_ACTIVITYADDITIONS@
233
240
234
241
// Native event bindings
235
- GLSurfaceView mGLView;
242
+ static GLSurfaceView mGLView = null ;
236
243
native void nativeEvent(int t, int x, int y);
237
244
static { System.loadLibrary("payloadshared"); }
238
245
// OpenURL code
@@ -259,6 +266,7 @@ class xGLSurfaceView extends GLSurfaceView {
259
266
setRenderer(renderer);
260
267
}
261
268
public boolean onTouchEvent(final MotionEvent event) {
269
+ super.onTouchEvent(event);
262
270
t=0;
263
271
x=(int)event.getX(); y=(int)event.getY();
264
272
switch (event.getAction()&MotionEvent.ACTION_MASK) {
0 commit comments