gpt4 book ai didi

java - requestFeature() before adding content error when trying to make AndEngine work with Google Play Game Service

转载 作者:行者123 更新时间:2023-11-30 03:28:03 25 4
gpt4 key购买 nike

我正在开发一款使用 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(以前只是 Activity )

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
  • 从 Google Play 游戏服务的 BaseGameUtils 获取的 BaseGameActivity 和 GameHelper.java。

最佳答案

好的,这就是我所做的:

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

    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>

关于java - requestFeature() before adding content error when trying to make AndEngine work with Google Play Game Service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17930196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com