首页 > 编程知识 正文

简述android四大组件,android 四大组件详解

时间:2023-05-04 14:34:11 阅读:149632 作者:3513

一.安卓四大组件

1 .安卓四大组件

活动活动活动

广播收件人BroadcastReceiver

服务服务服务

内容提供者内容提供者

2.Android四个组件的通用性

1 )定义:都是继承相应组件的类。

2 )清单文件配置)养成在创建组件类后立即合并清单文件中的APP的习惯

来设置并添加name属性。 属性值是类的完整包名称。

Activity组件配置选项卡

broadcast接收器配置选项卡

服务配置选项卡

内容提供器配置选项卡

3.Android四个组件的区别

1 )功能不同

2 )生命周期不同

二.意图

1 .意图(Intent )意图介绍

我认为没有必要再说一遍这个名词的概念。 因为官方文件叙述得非常详细:

anintentisanabstractdescriptionofanoperationtobeperformed.it

can be used

with

这意味着它是对Intent执行的操作的抽象描述,可用于打开1

发送到个Activity或感兴趣的广播收件人的BroadcastReceiver组件、后台服务

服务交流。 当然,也可以在APP应用程序之间交换信息。

有意作用:调用组件并传递数据(putExtra和getXxxExtra方法)。

因此,我们的意图是与Android的ContentProvider组件以外的组件建立关系。 关于是什么关系,后来的博客

在文章中详细叙述。 意图分类

意图分为两类。 显示意图和隐含意图显示意图。 直接从类名创建的意图称为显示意图。 一般的结构形式如下。

用. class构建的所有Intent都表示意图,一般有两种方法

ComponentName :组件描述对象

典型的结构格式: component name (APP应用程序包名称,完整的类名) ) ) ) ) ) ) ) )。

intent.setcomponent(cn;

直接在new Intent (上下文、类字节码;

显示意图通常用于启动当前APP应用程序中活动的Activity、服务服务,或在当前APP应用程序中将意图发送到广播接收方的BroadcastReceiver。 由于使用了类名且目标是唯一的,因此安全性较高。 目标不需要在列表中放置意图筛选器。

隐式意图:隐式意图通常使用空构造函数构建实例,并使用几个setXxx方法设置与启动目标方法过滤器匹配的信息。 隐式意图通常用于在其他APP应用程序中启动活动的Activity、服务服务,或在其他APP应用程序中将意图发送到广播收件人的BroadcastReceiver。 例如,启动系统附带的APP应用程序。

由于匹配不成功或可能有多个匹配结果,因此安全性较差。 目标必须在列表中放置意图筛选器。

当然,只要为清单配置了意图过滤器,隐式意图也可以用于启动APP应用程序中的目标组件。

:在非Activity (如Service )中使用意图启动Activity时,请确保将其添加到意图中

标记为intent.setflags (intent.flag _ activity _ new _ task ),为activity创建堆栈环境

—为activity打开startActivity,为服务打开startService。

2 .意图过滤器介绍:

查看官方文档:

structureddescriptionofintentvaluestobematched.anintentfiltercanmatchagainstactions、categories、anddata (

and/or path )

inan intent.italsoincludesa ' priority ' value which is

使用订单多项

匹配过滤器。

intentfilterobjectsareoftencreatedinxmlaspartofapackage ' s

这是因为,配置意图的值的记述是acion、category、data

可以使意图一致。 意图筛选器还具有“优先级”值,用于多个配置的意图

过滤器进行

排序。

通常意图过滤器是在清单文件中用intent-filter标签进行配置的,而需要定

义三个组件结点中。

意图过滤器的作用:匹配意图意图过滤器匹配规则

Filter Rules

A match is based on the following rules.  Note that

for an IntentFilter to match an Intent, three conditions must hold:

the action and category must match, and

the data (both the data type and data scheme+authority+path if specified) must match.

Actionmatches if any of the given values match the

Intent action; if the filter

specifies no actions, then it will only match

Intents that do not contain an action.

(只要过滤器里至少有1个action与Intent对象匹配即可)

】】action表示动作,就是想要做的事情的名称。

Categoriesmatch if all of the categories in

the Intent match categories given in the

filter.  Extra categories in the

filter that are not in the Intent will not cause the

match to fail.  Note

that unlike the action, an IntentFilter with no categories

will     only match an Intent that does not have any categories.

(过滤器里的所有category必需与Intent里的所有category一一匹配)

】】最常用的取值就2种情况

启动界面需

要配置

Data Schemematches if any of the given values match the

Intent data's scheme.

The

Intent scheme is determined by calling Note that

scheme matching here is case sensitive, unlike

formal RFC schemes!  You should thus

always use lower case letters

for your schemes.

(比如排打电话时创建的Intent对象,需要设置setData("tel:" + 电话号码),这个"tel:"就是data

scheme)

】】最常用的取值package、file、tel

Data Type matches if any of the given values match the

Intent type.  The Intent

type

is determined by calling

the MIME sub-type, in both the Intent and IntentFilter, so that the

type "audio/*"

will match "audio/mpeg", "audio/aiff", "audio/*", etc. Note that MIME type matching

here is case sensitive, unlike

formal RFC MIME types!  You should thus always use

lower case letters

for your MIME types.

Intent拓展功能1:android拍照,调用系统相册,相片上传

补充:欲知详情,请查看Android官方文档。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。