简体   繁体   English

Libgdx Android:onCreate()之后未调用方法onStart()

[英]Libgdx Android: method onStart() not called after onCreate()

onStart() onStart()

I know that onStart() method is called after onCreate() ( via Activity Lifecycle documentation ), but in my LibGDX project this doesn't happen. 我知道onStart()方法是在onCreate()之后(通过Activity Lifecycle文档 )调用的,但是在我的LibGDX项目中不会发生这种情况。 I' ve this code: 我有以下代码:

@Override
protected void onStart()
{
    super.onStart();
    Gdx.app.debug(TAG, "onStart");
}

but the string in debug terminal appears only if I resume the app from background. 但是只有当我从后台恢复应用程序时,调试终端中的字符串才会出现。 I need to do stuff after the initialise of the activity, when it becomes visible. 活动初始化后,当它变得可见时,我需要做一些事情。

EDIT: MORE CODE 编辑:更多代码

public class AndroidLauncher extends AndroidApplication {

private final static String TAG = AndroidLauncher.class.getSimpleName();

GoogleResolver googleResolver;

GoogleSignInAccount acct;
private Preferences googlePrefs;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    googleResolver = new GoogleResolverAndroid();
    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    config.useImmersiveMode = true;
    config.useGyroscope = false;
    config.useCompass = false;
    config.useAccelerometer = false;

    GoogleLoginHandler.getInstance().setContext(this.getContext());
    GoogleLoginHandler.getInstance().startApiClient();
    GameManager.getInstance().listener = googleResolver;

    initialize(new MainCrucy(), config);

    googlePrefs = Gdx.app.getPreferences(GOOGLE_PREF);
    GoogleLoginHandler.getInstance().mGooglePrefs =  Gdx.app.getPreferences(GOOGLE_PREF);

}

@Override
protected void onStart()
{
    super.onStart();
    Gdx.app.debug(TAG, "onStart");

    OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(GoogleLoginHandler.getInstance().getGoogleApiClient());
    if (opr.isDone())
    {
        Gdx.app.debug(TAG, "Loggato");
        GoogleSignInResult result = opr.get();
        handleSignInResult(result);
    } else {
        opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
            @Override
            public void onResult(GoogleSignInResult googleSignInResult) {
                handleSignInResult(googleSignInResult);
            }
        });
    }
}

This is what I do. 这就是我的工作。 But onStart() does anything 但是onStart()可以做什么

How long do you wait after launching you application? 启动应用程序后,您需要等待多长时间?

You have to remember that your app can take time to Start. 您必须记住,您的应用可能需要一些时间才能开始。 If what you say is true than you wouldn't see Gdx debug - it's still fires at onStart(). 如果您说的是对的,那么您将看不到Gdx调试-它仍然会在onStart()上触发。

So I assume: 所以我假设:

  • you launch an app 您启动一个应用程序
  • you don't want to wait so you minimize that 您不想等待,因此可以将其最小化
  • you open it and onStart() ends and you see debug logs 您打开它,onStart()结束,您会看到调试日志

By the way, could you show more code? 顺便说一句,您可以显示更多代码吗?

In the meantime look at the life cycle of Android app. 同时查看Android应用程序的生命周期。 Android lifecycle Android生命周期

You can't use Gdx.app.debug() before the Libgdx application has had a chance to start up. Libgdx应用程序有机会启动之前,您不能使用Gdx.app.debug() I'm not positive if this happens before onStart() because libgdx doesn't run on the UI thread. 我不太肯定这是否发生在onStart()之前,因为libgdx不在UI线程上运行。 Also, you must also use Gdx.app.setLogLevel(Application.LOG_DEBUG) first or calls to Gdx.app.debug() will do nothing. 另外,您还必须首先使用Gdx.app.setLogLevel(Application.LOG_DEBUG)否则调用Gdx.app.debug()将无济于事。

But you can just use Android's Log.d() instead. 但是您可以只使用Android的Log.d()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM