Repository: go
Issue: x/mobile: preserve eglContext when activity paused on Android
Labels: mobile

I have read some code in `x/mobile/app`, specially, `android.c` and `android.go`.  Gomobile will create Surface and eglContext very time when application resumed:
```
// android.go
case w := <-windowRedrawNeeded:
    if C.surface == nil {
		if errStr := C.createEGLSurface(w); errStr != nil {
			return fmt.Errorf("%s (%s)", C.GoString(errStr), eglGetError())
		}
	}
	theApp.sendLifecycle(lifecycle.StageFocused)
	widthPx := int(C.ANativeWindow_getWidth(w))
	heightPx := int(C.ANativeWindow_getHeight(w))
	theApp.eventsIn <- size.Event{
		WidthPx:     widthPx,
		HeightPx:    heightPx,
		WidthPt:     geom.Pt(float32(widthPx) / pixelsPerPt),
		HeightPt:    geom.Pt(float32(heightPx) / pixelsPerPt),
		PixelsPerPt: pixelsPerPt,
		Orientation: orientation,
	}
	theApp.eventsIn <- paint.Event{External: true}
case <-windowDestroyed:
	if C.surface != nil {
		if errStr := C.destroyEGLSurface(); errStr != nil {
			return fmt.Errorf("%s (%s)", C.GoString(errStr), eglGetError())
		}
	}
	C.surface = nil
	theApp.sendLifecycle(lifecycle.StageAlive)	
// android.c
char* createEGLSurface(ANativeWindow* window) {
	char* err;
	EGLint numConfigs, format;
	EGLConfig config;
	EGLContext context;

	if (display == 0) {
		if ((err = initEGLDisplay()) != NULL) {
			return err;
		}
	}

	if (!eglChooseConfig(display, RGB_888, &config, 1, &numConfigs)) {
		return "EGL choose RGB_888 config failed";
	}
	if (numConfigs <= 0) {
		return "EGL no config found";
	}

	eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
	if (ANativeWindow_setBuffersGeometry(window, 0, 0, format) != 0) {
		return "EGL set buffers geometry failed";
	}

	surface = eglCreateWindowSurface(display, config, window, NULL);
	if (surface == EGL_NO_SURFACE) {
		return "EGL create surface failed";
	}

	const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
	context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);

	if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
		return "eglMakeCurrent failed";
	}
	return NULL;
}

char* destroyEGLSurface() {
	if (!eglDestroySurface(display, surface)) {
		return "EGL destroy surface failed";
	}
	return NULL;
}
```
This will cause the application lost eglContext when activity is paused(eg: press Home).  A simple way to avoid this is to preserve the eglContext(only destroy Surface) and reuse it when needed. I have also make some research:
1. [Rethink how JNI and Map interact in lifecycle](https://github.com/mapbox/mapbox-gl-native/issues/578)
2. [100% NDK version of setPreserveEGLContextOnPause?](https://groups.google.com/forum/#!topic/android-ndk/jwVMF6zINus)
3. [ndk_helper/GLContext.cpp](https://android.googlesource.com/platform/development/+/19f647e/ndk/sources/android/ndk_helper/GLContext.cpp)

PS: The sample app [basic](https://github.com/golang/mobile/tree/master/example/basic) don't have the problem, cause it recreate the shader/index-buffer/vertex-buffer each time the window recreated, but it's impossible in a game with large amount of textures and buffers .