先执行application的name对应的类呢还是activity中的name对应的类?

2015-01-27 14:08:03 · 作者: · 浏览: 28

今天找程序入口发现了下面的情况有两个name我就写了个测试程序大致如下:

先看mainfest.xml

android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:name="com.example.test1.app"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:name="com.example.test1.MainActivity"
android:label="@string/app_name" >







k看app

package com.example.test1;


import android.app.Application;
import android.os.Bundle;
import android.util.Log;


public class app extends Application{
public void onCreate(){

super.onCreate();
Log.d("tt","application");
}


}


看activity如下

public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("tt","activity");
new app();

}

最后我们来看日志文件就清楚了:

10-28 15:40:54.915: D/tt(4116): application

10-28 15:40:55.525: D/tt(4116): activity\

这里就是说application 的name对应了类是在程序安装时候就创建了

然后我第二次打开如下:

\

只有一个信息<??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+YW5kcm9pZC5hcHAuQXBwbGljYXRpb248YnI+CkJhc2UgY2xhc3MgZm9yIHRob3NlIHdobyBuZWVkIHRvIG1haW50YWluIGdsb2JhbCBhcHBsaWNhdGlvbiBzdGF0ZS4gWW91IGNhbiBwcm92aWRlIHlvdXIgb3duIGltcGxlbWVudGF0aW9uIGJ5IHNwZWNpZnlpbmcgaXRzIG5hbWUgaW4geW91ciBBbmRyb2lkTWFuaWZlc3QueG1s"s tag, which will cause that class to be instantiated for you when the process for your application/package is created.
Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's tag, which will cause that class to be instantiated for you when the process for your application/package is created.