http://www.csdn.net/ http://www.arm.com/zh/ https://www.kernel.org/ http://www.linuxpk.com/ http://www.51develop.net/ http://linux.chinaitlab.com/ http://www.embeddedlinux.org.cn http://bbs.pediy.com/
分类: Android平台
2014-11-24 15:19:24
android应用程序,由一到多个Activity组成.每个Activity没有很紧密的联系,因为我们可以在自己的程序中调用其它Activity,特别是调用自己的代码之外生成的Activity,比如android提供的发短信或者打电话的Activity.
Intent call = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phonenumber);
startActivity(call);
Intent sms = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:"+phonenumber);
startActivity(sms);
从这点上看,android应用程序实际上是由多个Activity按照一定的次序拼装起来的,只不过拼装的过程中,后台传递了一些数据,使得各个Activity之间能比较好的衔接起来.
扯了这么多,其实我的意思还是想说,android应用程序中,并没有像c++和java这样有main函数来作为应用程序的入口.android应用程序提供的是入口Activity,而非入口函数.
在eclipse中创建一个android应用程序的时候,默认会创建一个Activity.这个Activity实际上就是入口Activity了.从哪里定义它是Activity呢?AndroidManifest.xml文件中定义了整个android应用所包含的Activity.默认生成的Activity的定义为:
action节点中的android.intent.action.MAIN表明它所在的Activity是整个应用程序的入口点.而category中的android.intent.category.LAUNCHER意思是把这个Activityg归属到加载器类,即把这个Activity标注为自动会加载和启动的Activity,这样程序启动时候就先加载这个Activity了.参考手册上是这么说的----"the LAUNCHER category says that this entry point should be listed in the application launcher."意思和我理解的有出入.不过意思都是说这个Activity要被应用程序加载.
我们可以对比下eclipse中console端输出的日志来看下.初始,我把
[2011-08-11 09:29:10 - lifecycle_test] ------------------------------
[2011-08-11 09:29:10 - lifecycle_test] Android Launch!
[2011-08-11 09:29:10 - lifecycle_test] adb is running normally.
[2011-08-11 09:29:10 - lifecycle_test] No Launcher activity found!
[2011-08-11 09:29:10 - lifecycle_test] The launch will only sync the application package on the device!
[2011-08-11 09:29:10 - lifecycle_test] Performing sync
[2011-08-11 09:29:10 - lifecycle_test] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'myavd_2.2'
[2011-08-11 09:29:15 - lifecycle_test] Application already deployed. No need to reinstall.
[2011-08-11 09:29:15 - lifecycle_test] \lifecycle_test\bin\lifecycle_test.apk installed on device
[2011-08-11 09:29:15 - lifecycle_test] Done!
[2011-08-11 09:30:47 - lifecycle_test] ------------------------------
[2011-08-11 09:30:47 - lifecycle_test] Android Launch!
[2011-08-11 09:30:47 - lifecycle_test] adb is running normally.
[2011-08-11 09:30:47 - lifecycle_test] Performing test.activity.leipei.activity01 activity launch
[2011-08-11 09:30:47 - lifecycle_test] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'myavd_2.2'
[2011-08-11 09:30:47 - lifecycle_test] Uploading lifecycle_test.apk onto device 'emulator-5554'
[2011-08-11 09:30:47 - lifecycle_test] Installing lifecycle_test.apk...
[2011-08-11 09:30:54 - lifecycle_test] Success!
[2011-08-11 09:30:55 - lifecycle_test] Starting activity test.activity.leipei.activity01 on device emulator-5554
[2011-08-11 09:30:57 - lifecycle_test] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=test.activity.leipei/.activity01 }