Launcher与普通Activity的区别

Launcher与普通Activity的区别

分类: Android应用   692人阅读  评论(0)  收藏  举报

目录(?)[+]

1.    Intent-Filter

[java]  view plain copy
  1.  <intent-filter>  
  2.   
  3.        <action android:name="android.intent.action.MAIN" />  
  4.   
  5.        <category android:name="android.intent.category.HOME" />  
  6.   
  7.        <category android:name="android.intent.category.DEFAULT"/>  
  8.   
  9.        <category android:name="android.intent.category.MONKEY"/>  
  10.   
  11.        <category android:name="android.intent.category.LAUNCHER"/>  
  12.   
  13. </intent-filter>  
    android.intent.action.MAIN决定应用程序最先启动的Activity

    android.intent.category.LAUNCHER决定应用程序是否显示在程序列表里

    当Intent通过startActivity被传递出后,Android系统会找到适合的activity去响应这个intent。

    与此类似,startService,sendBroadcast之后都会由Android去寻找对应的程序。

    一个Intent对象是一个信息包。它包含了要接收此Intent的组件需要的信息(例如需要的动作和动作需要的信息)和 android 系统需要的信息(要处理此Intent的组件的类别和怎样启动它)

    主要用来指明Activity,Service, Broadcast Receiver可以响应哪些隐式intents。

action

    一个字符串,代表要执行的动作。如果学过Structs2的同学应该不会陌生,所谓的action就是发送一个特定的请求,然后,由一个符合这个请求的activity响应。Intent类中定义了许多动作常量。如下:

常量

目标组件

Action

ACTION_CALL

activity

初始化一个电话呼叫

ACTION_EDIT

activity

显示用户要编辑的数据

ACTION_MAIN

activity

将该Activity作为task的第一个Activity ,没有数据输入,也没有数据返回

ACTION_SYNC

activity

在设备上同步服务器上的数据

ACTION_BATTERY_LOW

broadcast receiver

电量不足的警告

ACTION_HEADSET_PLUG

broadcast receiver

耳机插入设备,或者从设备中拔出

ACTION_SCREEN_ON

Broadcast receiver

屏幕已经点亮

ACTION_TIMEZONE_CHANGED

Broadcast receiver

时区设置改变

category

    一个字符串, 包含了处理该Intent的组件的种类信息, 起着对action的补充说明作用。

    一个Intent对象可以有任意多个 category。和action 一样, 在Intent class 中也定义了几个 category 常量。。 如下:

Constant

Meaning

CATEGORY_BROWSABLE

目标Activity可以使用浏览器显示数据

CATEGORY_GADGET

The activity can be embedded inside of another activity that hosts gadgets.

该activity可以被包含在另外一个装载小工具的activity中.

CATEGORY_HOME

The activity displays the home screen, the first screen the user sees when the device is turned on or when the HOME key is pressed.

CATEGORY_LAUNCHER

可以让一个activity出现在launcher

CATEGORY_PREFERENCE

该activity是一个选项面板

CATEGORY_DEAULT

该activity是否可以接收到隐式Intents。说明除了程序入口点的filter不需要包含DEFAULT之外,其余所有的activity都要包含DEFAULT;因为如果那些activity不包含DEFAULT,将无法接收到主Activity的任何调用命令。 如SecondActivity中必须包含包名和DEFAULT的category.

注意
A.任何一个需要隐式启动的Activity都必须要有这项:
category android:name="android.intent.category.DEFAULT"
例外情况是:
android.intent.category.MAIN和android.intent.category.LAUNCHER的filter中没有必要加入android.intent.category.DEFAULT,当然加入也没有问题
B. 当匹配不上任何Activity的话,会发生异常,跳出对话框:很抱歉...某某应用程序意外停止,请重试。
 

2.    普通的Activity

[java]  view plain copy
  1. <span style="font-size:18px;"> </span><intent-filter>  
  2.   
  3. <!-- The MAIN action describes a main entrypoint into an  
  4.   
  5.                      activity, without anyassociated data. -->  
  6.   
  7. <actionandroid:name="android.intent.action.MAIN" />  
  8.   
  9.    
  10.   
  11. <!-- This places this activity into the main app list. -->  
  12.   
  13. <categoryandroid:name="android.intent.category.LAUNCHER" />  
  14.   
  15. </intent-filter>  


    其中的MAIN表示这是该应用启动的第一个Activity, 而LAUNCHER表示此应用将被加载到Launcher的应用程序列表中. 

3.   Launcher的特殊处

Launcher的intent-filter是这样的,

[java]  view plain copy
  1. <action android:name="android.intent.action.MAIN"/>  
  2.   
  3. <categoryandroid:name="android.intent.category.HOME"/>  
  4.   
  5. <categoryandroid:name="android.intent.category.DEFAULT"/>  
  6.   
  7. <categoryandroid:name="android.intent.category.MONKEY"/>  
    这个Activity是系统启动后要执行的第一个Activity. 在你的Activity的AndroidManifest.xml中加入这几个过滤条件, 你的应用就能取代Launcher的位置了.

    HOME表示该Activity可以作为Launcher, 即系统的第一个应用. 

4. Launcher在系统中的调用过程



 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值