1

我正在开发一款使用 AndEngine 的游戏。

AndEngine 有一个“BaseGameActivity”,Google Play 游戏服务也有。我不得不将 BaseGameActivity 从 AndEngine 重命名为 AEBaseGameActivity 并将其作为父类 BaseGameActivity 而不是 Activity。

但它给了我这个错误:

Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
        at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:226)
        at org.andengine.util.ActivityUtils.requestFullscreen(ActivityUtils.java:56)
        at org.andengine.ui.activity.AEBaseGameActivity.applyEngineOptions(AEBaseGameActivity.java:427)
        at org.andengine.ui.activity.AEBaseGameActivity.onCreate(AEBaseGameActivity.java:83)

现在 AndEngine 有这段代码:

public static void requestFullscreen(final Activity pActivity) {
        final Window window = pActivity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        window.requestFeature(Window.FEATURE_NO_TITLE);
    }

如果我评论 requestFeature 行,我的项目就会运行!但它有一个丑陋的标题栏。

有没有人知道解决这个问题?

编辑,这里有更多代码:

PS:AEBaseGameActivity.php 扩展 BaseActivity 扩展 BaseGameActivity (以前只是活动)

AEBaseGameActivity.php

public abstract class AEBaseGameActivity extends BaseActivity implements IGameInterface, IRendererListener {
    @Override
    protected void onCreate(final Bundle pSavedInstanceState) {
        if(BuildConfig.DEBUG) {
            Debug.d(this.getClass().getSimpleName() + ".onCreate" + " @(Thread: '" + Thread.currentThread().getName() + "')");
        }

        super.onCreate(pSavedInstanceState);

        this.mGamePaused = true;

        this.mEngine = this.onCreateEngine(this.onCreateEngineOptions());
        this.mEngine.startUpdateThread();

        this.applyEngineOptions(); //REQUEST FULLSCREEN

        this.onSetContentView(); //SET CONTENT VIEW
    }

    ...

    private void applyEngineOptions() {
        final EngineOptions engineOptions = this.mEngine.getEngineOptions();

        if(engineOptions.isFullscreen()) {
            ActivityUtils.requestFullscreen(this); //ACTIVITY UTIL SHOWN LATER
        }

        ...
    }

    ...

    protected void onSetContentView() {
        this.mRenderSurfaceView = new RenderSurfaceView(this);
        this.mRenderSurfaceView.setRenderer(this.mEngine, this);

        this.setContentView(this.mRenderSurfaceView, AEBaseGameActivity.createSurfaceViewLayoutParams());
    }
}

ActivityUtils.java

public class ActivityUtils {

    public static void requestFullscreen(final Activity pActivity) {
        final Window window = pActivity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        window.requestFeature(Window.FEATURE_NO_TITLE); //IF COMMENTING THIS, THE GAME IS RUNNING
    }

    ...

}

编辑2:

代码基本上只有AndEngine,这里是原代码:

https://github.com/nicolasgramlich/AndEngine/tree/GLES2/src/org/andengine/ui/activity

我的变化:

  • 将 BaseGameActivity 重命名为 AEBaseGameActivity
  • BaseActivity 扩展 BaseGameActivity(取自 Google Play 游戏服务)而不是 Activity
  • BaseGameActivity 和 GameHelper.java 取自 Google Play 游戏服务的 BaseGameUtils。
4

2 回答 2

1

好的,这就是我所做的:

  • 我注释掉了导致问题的行(AndEngine 的 ActivityUtils.java 第 56 行)
  • 我在我的活动中添加了这个到 Android 清单:

    android:theme="@android:style/Theme.NoTitleBar"

它最终看起来像:

<activity
                android:name=".GameActivity"
                android:theme="@android:style/Theme.NoTitleBar"
                android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
于 2013-07-29T22:14:40.437 回答
0

例外requestFeature() must be called before adding content告诉一切

requestFullscreen()之前打电话setContenview()

编辑

之后尝试请求全屏super.onCreate()

@Override
protected void onCreate(final Bundle pSavedInstanceState) {
    super.onCreate(pSavedInstanceState);
    this.applyEngineOptions();  //REQUEST FULLSCREEN
于 2013-07-29T17:22:19.213 回答