简体   繁体   English

执行顺序混乱

[英]Confusion over execution order

I have a game application made up of several different activities. 我有一个由几个不同的活动组成的游戏应用程序。 The first to be called is a splash screen, when this completes, this finishes and starts up another activity via an intent. 第一个被称为启动屏幕,完成后将完成并通过意图启动另一个活动。 In order to have access to some global data that is consistent across all the activities, I also have a "globals" class like this: 为了访问在所有活动中都一致的某些全局数据,我还具有一个“ globals”类,如下所示:

public class Globals extends Application
{
  int global_variable_A;
  int global_variable_B;
  int global_variable_C;

  public void onCreate()
  {
    // stuff
  }
}

In the androidmanifest.xml I have the the following (amongst other things): 在androidmanifest.xml中,我有以下内容(以及其他内容):

<application
    android:icon="@drawable/mygame_icon"
    android:screenOrientation="portrait"
    android:label='"My Game"' android:name=".Globals">

<activity
    android:label="My Game"
    android:name=".Splash" 
    android:screenOrientation="portrait">
    <intent-filter >
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

My question now is, which will be executed first, the onCreate of Globals or the onCreate of Splash? 现在我的问题是,将首先执行Global的onCreate或Splash的onCreate吗? Or are they run at the same time on different threads? 还是它们同时在不同的线程上运行? I ask because I'm getting some inconsistent behaviour that would be explained if they were on different threads. 我问是因为我得到了一些不一致的行为,如果它们在不同的线程上,可以解释这些行为。

onCreate()全局偏离路线。首先执行应用程序,然后执行Activity,您可以通过在Application onCreate()方法中保留调试点来进行自我测试。

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

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