这是问题所在。为什么我的Surface视图不调用surfaceCreated()?
这是我的SurfaceView:
public class Controller extends SurfaceView implements SurfaceHolder.Callback {
private Thread thread;
private Context context;
public class Controller extends SurfaceView implements SurfaceHolder.Callback {
private Thread thread;
private Context context;
Controller(Context context) {
super(context);
this.context = context;
this.setClickable(true);
this.setFocusable(true);
setBackground();
this.setOnTouchListener(new SurfaceOnTouchListener(context));
Log.d(TAG, "I get this log");
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG,"I don't receive this log in the logcat");
this.thread = new Thread(holder, this);
thread.run();
thread.setRunning(true);
}
对此,我有一个onDraw()
方法,该方法似乎在创建整个类时仅运行一次,但显然在surfaceCreated()
方法之前运行。此方法及其后的所有代码都将被忽略,包括线程。
我怀疑是由于this.setOnTouchListener(new SurfaceOnTouchListener(context));
我在那里使用GestureDetector,特别是onFling()方法,有趣的是,在“控制器”之后,我总是总是得到两个关于系统日志(我不理解)运行”日志有效:
2019-01-19 20:27:24.277 4517-4517/com.example.myapplication2 D/ContentValues: controller
2019-01-19 20:27:24.351 4517-4536/com.example.myapplication2 D/OpenGLRenderer: HWUI GL Pipeline
2019-01-19 20:27:24.381 4517-4536/com.example.myapplication2 I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 02019-01-19 20:27:24.039 4517-4517/? I/zygote: Not late-enabling -Xcheck:jni (already on)
2019-01-19 20:27:24.052 4517-4517/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
2019-01-19 20:27:24.166 4517-4517/com.example.myapplication2 I/InstantRun: starting instant run server: is main process
2019-01-19 20:27:24.242 4517-4517/com.example.myapplication2 D/ContentValues: Main Act
2019-01-19 20:27:24.277 4517-4517/com.example.myapplication2 D/ContentValues: controller Runs
2019-01-19 20:27:24.351 4517-4536/com.example.myapplication2 D/OpenGLRenderer: HWUI GL Pipeline
2019-01-19 20:27:24.381 4517-4536/com.example.myapplication2 I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-01-19 20:27:24.381 4517-4536/com.example.myapplication2 I/OpenGLRenderer: Initialized EGL, version 1.4
2019-01-19 20:27:24.381 4517-4536/com.example.myapplication2 D/OpenGLRenderer: Swap behavior 1
2019-01-19 20:27:24.381 4517-4536/com.example.myapplication2 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-01-19 20:27:24.381 4517-4536/com.example.myapplication2 D/OpenGLRenderer: Swap behavior 0
2019-01-19 20:27:24.393 4517-4536/com.example.myapplication2 D/EGL_emulation: eglCreateContext: 0xc929f6c0: maj 2 min 0 rcv 2
2019-01-19 20:27:24.395 4517-4536/com.example.myapplication2 D/EGL_emulation: eglMakeCurrent: 0xc929f6c0: ver 2 0 (tinfo 0xdc1bd3a0)
2019-01-19 20:27:24.442 4517-4517/com.example.myapplication2 D/ContentValues: Drawing...
2019-01-19 20:27:24.443 4517-4536/com.example.myapplication2 D/EGL_emulation: eglMakeCurrent: 0xc929f6c0: ver 2 0 (tinfo 0xdc1bd3a0)
但是,在删除整个customOnTouchListener之后,问题仍然存在,所以我想这不是问题。 有什么想法可能导致这一切吗?