Application Fundamentals 应用基础

一个Intent可以被Intent对象创建,它定义了一条消息来激活一个指定的组件或者一类特定的组件,一个Intent可以分别显示或者隐式指定。

For activities and services, an intent defines the action to perform (for example, to “view” or “send” something) and may specify the URI of the data to act on (among other things that the component being started might need to know). For example, an intent might convey a request for an activity to show an image or to open a web page. In some cases, you can start an activity to receive a result, in which case, the activity also returns the result in an [Intent]( ) (for example, you can issue an intent to let the user pick a personal contact and have it returned to you—the return intent includes a URI pointing to the chosen contact)。

Intent可以传递给组件信息,比如显示一张图片或者打开一个网页,在一些情况下,你可以开启一个activity来接受结果,并且这个activity可以返回结果到Intent中。

For broadcast receivers, the intent simply defines the announcement being broadcast (for example, a broadcast to indicate the device battery is low includes only a known action string that indicates “battery is low”)

对于广播接受者,Intent简单的定义了一个通知。

The other component type, content provider, is not activated by intents. Rather, it is activated when targeted by a request from a [ContentResolver]( ). The content resolver handles all direct transactions with the content provider so that the component that’s performing transactions with the provider doesn’t need to and instead calls methods on the [ContentResolver]( ) object. This leaves a layer of abstraction between the content provider and the component requesting information (for security).

对于其他组件类型,内容提供者,不是被Intent所激活,而是被目标contentResolver所激活。

  • You can start an activity (or give it something new to do) by passing an [Intent]( ) to [startActivity()]( ) or [startActivityForResult()]( ) (when you want the activity to return a result).

你可以通过startActivity或者startActivtiyForRespult来启动一个activity

  • You can start a service (or give new instructions to an ongoing service) by passing an [Intent]( ) to [startService()]( ). Or you can bind to the service by passing an[Intent]( ) to [bindService()]( ).

你可以启动一个service,通过Intent到startService,或者你可以绑定一个服务通过bindService

  • You can initiate a broadcast by passing an [Intent]( ) to methods like [sendBroadcast()]( )[sendOrderedBroadcast()]( ), or [sendStickyBroadcast()]( ).

你可以初始化一个broadcast通过传一个 [sendBroadcast()]( )[sendOrderedBroadcast()]( ), or [sendStickyBroadcast()]( ).

  • You can perform a query to a content provider by calling [query()]( ) on a [ContentResolver]( ) 你可以执行一个查询通过调用 `[query()]( )` on a `[ContentResolver]( ) `

The Manifest File


Before the Android system can start an application component, the system must know that the component exists by reading the application’sAndroidManifest.xml file (the “manifest” file). Your application must declare all its components in this file, which must be at the root of the application project directory.

在Android系统启动一个程序组件之前,系统必须通过读取AndroidManifest文件来知道需要使用哪些组件,你的程序必须声明所有的组件在那个文件里面,文件在工程的根目录下。

The manifest does a number of things in addition to declaring the application’s components, such as:

  • Identify any user permissions the application requires, such as Internet access or read-access to the user’s contacts.

确认程序访问网络,读取用户通讯录的权限等

  • Declare the minimum API Level required by the application, based on which APIs the application uses.

声明程序的最低的APILevel

  • Declare hardware and software features used or required by the application, such as a camera, bluetooth services, or a multitouch screen.

声明程序需要使用到硬件与软件的功能

API libraries the application needs to be linked against (other than the Android framework APIs), such as the Google Maps library.

除了Android Frame API文件里面的Library需要进行链接

Declaring components

如下声明Manifest文件

[html] view plain copy print ?

  1. <?xml** version\="1.0" encoding\="utf-8"**?>

  2. <manifest … >

  3. <application android:icon=“@drawable/app_icon.png” … >

  4. <activity android:name=“com.example.project.ExampleActivity”

  5. android:label=“@string/example_label” … >

  6. </activity>

  7. </application>

  8. </manifest>

<?xml version="1.0" encoding="utf-8"?>

设置应用的图标

In the [<activity>]( ) element, the android:name attribute specifies the fully qualified class name of the [Activity]( ) subclass and the android:label attributes specifies a string to use as the user-visible label for the activity.

设置activity的显示名称

You must declare all application components this way:

  • [<activity>]( ) elements for activities

  • [<service>]( ) elements for services

  • [<receiver>]( ) elements for broadcast receivers

  • [<provider>]( ) elements for content providers

使用上面的标签进行相应的声明

Activities, services, and content providers that you include in your source but do not declare in the manifest are not visible to the system and, consequently, can never run.However, broadcast receivers can be either declared in the manifest or created dynamically in code (as [BroadcastReceiver]( ) objects) and registered with the system by calling [**registerReceiver()**]( ) 没有声明的组件对系统不可见,也不可以运行,然而,broadcast receiver可以在代码中被动态的创建,并且被系统使用registerReceiver进行注册

Declaring component capabilities

As discussed above, in Activating Components, you can use an [Intent]( ) to start activities, services, and broadcast receivers. You can do so by explicitly naming the target component (using the component class name) in the intent. However, the real power of intents lies in the concept of intent actions. With intent actions, you simply describe the type of action you want to perform (and optionally, the data upon which you’d like to perform the action) and allow the system to find a component on the device that can perform the action and start it. If there are multiple components that can perform the action described by the intent, then the user selects which one to use.

我们可以使用Intent来启动activity,service,broadcast Receiver。你可以在Intent中明确指定目标组件。然而Intent的体现依赖于Intent动作的概念。在Intent动作下,你可以简单的描述你希望执行的动作类型,并且允许系统在设备上找到相应的组件并启动它。如果有多种组件可以执行Intent描述的这个动作,那么用户来选择使用哪一个

The way the system identifies the components that can respond to an intent is by comparing the intent received to the intent filters provided in the manifest file of other applications on the device.

系统是与从Manifest文件中提供的Intent filter进行对比来选择相应的组件

When you declare a component in your application’s manifest, you can optionally include intent filters that declare the capabilities of the component so it can respond to intents from other applications. You can declare an intent filter for your component by adding an <intent-filter> element as a child of the component’s declaration element.

当你在应用的Manifest文件中声明一个组件时,你可以选择是否添加Intent filter,它用来声明组件相应其他应用Intent的能力。你可以使用  [<intent-filter>]( )标签作为组件声明标签的自标签来声明一个Intent filter。

Declaring application requirements

There are a variety of devices powered by Android and not all of them provide the same features and capabilities. In order to prevent your application from being installed on devices that lack features needed by your application, it’s important that you clearly define a profile for the types of devices your application supports by declaring device and software requirements in your manifest file. Most of these declarations are informational only and the system does not read them, but external services such as Android Market do read them in order to provide filtering for users when they search for applications from their device.

有许多不同的Android设备,并不是所有设备都提供同样的功能与能力。为了防止你的应用装上设备后却发现设备缺少应用需要的功能,必须清楚的在Manifest文件中为你的应用支持的设备类型与软件需要定义属性。大多数声明仅仅是个信息而系统并不读取他们,但是外部服务如Android market在他们从设备上查找应用时会去读取filter。

However, you can also declare that your applicaiton uses the camera, but does not require it. In that case, your application must perform a check at runtime to determine if the device has a camera and disable any features that use the camera if one is not available

你可以声明你的应用来使用camera,当并不是必须的。在那种情况下,你的应用在执行的时候会去验证是否这个设备具有camera,并且会在其中一个需要不能提供的时候关闭所有的功能。

下面是我们开发应用时需要考虑的设备属性:

Screen size and density:屏幕大小与分辨率

The screen sizes are: small, normal, large, and extra large.

The screen densities are: low density, medium density, high density, and extra high density.

By default, your application is compatible with all screen sizes and densities, because the Android system makes the appropriate adjustments to your UI layout and image resources. However, you should create specialized layouts for certain screen sizes and provide specialized images for certain densities, using alternative layout resources, and by declaring in your manifest exactly which screen sizes your application supports with the <supports-screens>element.

通常情况下,你的应用可以适应所有的屏幕大学与分辨率,因为Android系统会自动调整布局与图片资源。然而你需要为特定的屏幕大小指定布局文件,并指定特定的图像给确定的分辨率,使用可以替代的布局资源,并且在Manifest文件中正确的指出支持哪些屏幕大小。

Input configurations:输入配置

使用 [<uses-configuration>]( )标签来声明指定的输入方式,其实很少情况下需要那样做

Device features:设备功能

使用 `[<uses-feature>]( )标签来来声明设备是否有camera, a light sensor, bluetooth, a certain version of OpenGL, or the fidelity of the touchscreen等功能`

` `

`Platform Version:平台版本 `

` `

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
img

最后我想说

为什么很多程序员做不了架构师?
1、良好健康的职业规划很重要,但大多数人都忽略了
2、学习的习惯很重要,持之以恒才是正解。
3、编程思维没能提升一个台阶,局限在了编码,业务,没考虑过选型、扩展
4、身边没有好的架构师引导、培养。所处的圈子对程序员的成长影响巨大。

金九银十面试季,跳槽季,整理面试题已经成了我多年的习惯!在这里我和身边一些朋友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。

附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题(含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)

里面包含不同方向的自学编程路线、面试题集合/面经、及系列技术文章等,资源持续更新中…

友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。**

附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题(含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)

[外链图片转存中…(img-HO6KvAxn-1711926486798)]

里面包含不同方向的自学编程路线、面试题集合/面经、及系列技术文章等,资源持续更新中…

本文已被CODING开源项目:《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》收录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值