简体   繁体   中英

How does android loads an activity on screen?

In my application i have created an activity which is showing simple hello world message. In "AndroidManifest.xml" file i set label attribute as="welcome":

<activity
    android:name="com.example.dmo.MainActivity"
    android:label="Welcome" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

in in MainActivity.java file in onCreate() method I set the title of an activity as "Hello world" using setTitle("Hello World ");

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        setTitle("Hello World .");
    }

Now my issue is that . . When I run my app First of all only title bar is shown with title set as "Welcome" ie set from androidManifest.xml file . . Then after the delay of some miliseconds remaining GUI is displayed and title changes to "Hello World" ie from setTitle() in onCreate() . According to my knowledge onCreate() is the first method that is executed.

  1. Now what I want is , I don't want this delay to be happened and activity should directly show the title from method ie Hello World .

  2. I also want to know that why this delay occures and only title bar is shown first and rest GUI later.

Note: My condition is that I cant remove label from my manifest.xml file and still I want to do as mentioned above.

just do this

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
setTitle("Hello World .");        
setContentView(R.layout.activity_main);


}

you need to decide to change title before loading layout

The simple to display Hello world in title is

  • Rename welcome to Hello world and no need to settitle on oncreate method

And the delay is due to loading the MainActivity . First of xml data of the activity is loaded and then oncreate is called which calls its super class and then only settitle is called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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