[英]Libgdx Android: method onStart() not called after onCreate()
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.
活动初始化后,当它变得可见时,我需要做一些事情。
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: 所以我假设:
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.