在onRestart / onResume之后,surfaceCreated调用了两次

时间:2015-10-20 09:28:25

标签: android surfaceview allegro

当我的应用程序暂停然后重新启动时,我注意到我已经两次获得surfaceCreated回调。什么更有趣,第一次在我的代码创建新曲面之前调用它。这会破坏各种混乱,我想了解它为什么会发生,我怎样才能过滤掉那些虚假的回调而不对它做出反应,或者阻止它被调用。

以下是logcat的相关摘录:

10-20 11:35:21.834 24548 24548 D AllegroEGL: destroying egl_Surface
10-20 11:35:21.844 24548 24548 D AllegroEGL: destroying egl_Context
10-20 11:35:22.874 24548 24548 D AllegroSurface: surfaceDestroyed end
10-20 11:35:22.884 24548 24548 D AllegroActivity: onSaveInstanceState
10-20 11:35:22.884 24548 24548 D AllegroActivity: onStop.
// Here, the game is paused and restored
10-20 11:35:27.524 24548 24548 D AllegroActivity: onRestart.
10-20 11:35:27.524 24548 24548 D AllegroActivity: onStart.
10-20 11:35:27.524 24548 24548 D AllegroActivity: onResume
10-20 11:35:27.624 24548 24548 I allegro : android  D 24548:         android_system.c:303  Java_org_liballeg_android_AllegroActivity_nativeOnResume [  69.49768] resume activity
10-20 11:35:27.624 24548 24548 I allegro : android  D 24548:     android_system.c:316  Java_org_liballeg_android_AllegroActivity_nativeOnResume [  69.49773] got display: 0x5d55fd20
10-20 11:35:27.624 24548 24548 D AllegroActivity: postCreateSurface
10-20 11:35:27.624 24548 24548 D AllegroActivity: onResume end
10-20 11:35:33.964 24548 24548 I Choreographer: Skipped 388 frames!  The application may be doing too much work on its main thread.
10-20 11:35:33.984 24548 24548 D AllegroSurface: surfaceCreated
// Later:
10-20 11:35:48.934 24548 24548 D AllegroActivity: createSurface
// ... lots of action ...
10-20 11:36:02.044 24548 24548 D AllegroActivity: createSurface end

postCreateSurface包含如下所示:

void postCreateSurface()
{
   try {
      Log.d("AllegroActivity", "postCreateSurface");

      handler.post(new Runnable() {
         public void run() {
            createSurface();
         }
      });
   } catch (Exception x) {
      Log.d("AllegroActivity", "postCreateSurface exception: " + x.getMessage());
   }
}

正如您所看到的,它调用" createSurface"功能,应记录" createSurface"和" createSurface end"进入logcat。事实确实如此 - 但仅限于" surfaceCreated"回调!

尝试使用此第一个表面导致GL_INVALID_OPERATION错误,因此它显然是错误的。

我不知道在这里发生了什么,我应该怎么做。

1 个答案:

答案 0 :(得分:0)

您在Surface View中所做的一些更改使其再次调用surfaceCreated(),例如:“ yourSurfaceView.getHolder()。setFormat(PixelFormat.TRANSPARENT)”将再次调用surfaceCreated()。