Android API Guides 学习笔记---Application Fundamentals(一)
今天开始学习google官网上的API guides ,主要读了Application Fundamentals这一章节,此章节介绍了一个App的基本组成,共包括四大部分内容.
1. Application Components(android应用程序的四大组件)
2. Activating Components(下面描述的组件用于激活上述四大组件)
3. The Manifest File(描述每个app的组件构成,能力及对系统的要求)
4. Application Resources(除了代码以外,还有图片/页面布局等其他配置)
下面逐一展开做记录,详细细节需要参考google官网http://developer.android.com/guide/components/fundamentals.html
Application Fundamentals
1. Application Components(android应用程序的组件)
Android application包含四大组件:
1) Activity: An activity represents a single screen with a user interface. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails.
NOTE: 一个application可以包含若干个activity,其他的app可以独立的调用本app的任意一个activity
2) Service: A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while the user is in a different application
NOTE: Service即没有UI的服务,可以被start或bind
3) Content provider: A content provider manages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage. Through the content provider, other applications can query or even modify the data (if the content provider allows it).
NOTE: Content Provider用来在不同app间共享数据
4) Broadcast receiver: A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. Applications can also initiate broadcasts—for example, to let other applications know that some data has been downloaded to the device and is available for them to use.
NOTE: Broadcast receiver没有UI,但是可以在status bar上创建alert通知用户事件发生. Although broadcast receivers don't display a user interface, they may create a status bar notificationto alert the user when a broadcast event occurs.
2. Activating Components(下面描述的组件用于激活上述四大组件)
1) Intent: Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an intent
NOTE: activities, services, and broadcast receivers这三大组件是由intent事件激活(启动),但是content provider不由Intent驱动,见下一条
2) Content Resolver: Content provider, is not activated by intents. Rather, it is activated when targeted by a request from a ContentResolver.
NOTE: The content resolver作为中间层负责处理其他组件与content provider之间的事务. 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.
对于四大组件的激活方式总结如下:
- You can start an activity (or give it something new to do) by passing an Intent to startActivity() orstartActivityForResult() (when you want the activity to return a result).
- You can start a service (or give new instructions to an ongoing service) by passing an Intent tostartService(). Or you can bind to the service by passing an Intent to bindService().
- You can initiate a broadcast by passing an Intent to methods like sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().
- You can perform a query to a content provider by calling query() on a ContentResolver.
3. The Manifest File(描述每个app的组件构成,能力及对系统的要求)
每个app在其根目录都放有一个文件AndroidManifest.xml: 用来描述此app的组件构成以及需求等等. Android系统在通过读取此manifest文件可以了解本app的需求和功能.
Manifest 文件的主要作用如下
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.
- 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 theGoogle Maps library.
- And more
1) Declaring components(用来声明app所包含的组件)
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
NOTE: Activities, services, and content providers 必须在Manifest中声明,否则不可见,也不可运行. 但是Broadcast receiver既可以在manifest中声明,也可以不在manifest中声明而是动态向system注册….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().
2) Declaring component capabilities(声明每个组件所具有的能力,如可以send,edit等…)
通过Intent Filter来声明每个组件的能力,也即app具有的能力(一个app具有若干个组件). 系统读取每个组件的intent filter字段,从而得知每个组件的能力.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.
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.
NOTE: 定位程序入口activity的方法: 查找manifest,<intent-filter>中有 MAIN 和LAUNCHER的 activity就是
3) Declaring application requirements(用来声明app对外界的需求)
Screen size and density: 对屏幕的尺寸和分辨率的要求,用<supports-screens> 字段来声明
Input configurations:对输入途径的要求, 用字段 <uses-configuration>来声明
Device features:对硬件的要求如蓝牙支持,相机支持,光感/重力感应器的支持等等,用字段 <uses-feature>声明
Platform Version: 要求的最低的android API level, 用 <uses-sdk> 字段声
4. Application Resources(除了代码以外,还有图片/页面布局等其他配置)
一个android的app除了java code以外,还需要包含其他的资源.如程序所需要的图片/动画/音视频/页面布局/不同语言/横竖屏显示调整等等. 这些储存在app的res文件夹中.
An Android application is composed of more than just code—it requires resources that are separate from the source code, such as images, audio files, and anything relating to the visual presentation of the application. For example, you should define animations, menus, styles, colors, and the layout of activity user interfaces with XML files. Using application resources makes it easy to update various characteristics of your application without modifying code(不用调整代码,只需要对应不同的配置文件就可以) and—by providing sets of alternative resources—enables you to optimize your application for a variety of device configurations (such as different languages and screen sizes).
Android API Guides 学习笔记---Application Fundamentals(一)的更多相关文章
- 【Android Api 翻译3】android api 完整翻译之Application Fundamentals (学习android必须知道的)
Android应用程序是用Java编程语言编写的.Android SDK工具把应用程序的代码.数据和资源文件一起编译到一个Android程序包中(这个程序包是以.apk为后缀的归档文件),一个Andr ...
- Android安装器学习笔记(一)
Android安装器学习笔记(一) 一.Android应用的四种安装方式: 1.通过系统应用PackageInstaller.apk进行安装,安装过程中会让用户确认 2.系统程序安装:在开机的时候自动 ...
- Rest API 开发 学习笔记(转)
Rest API 开发 学习笔记 概述 REST 从资源的角度来观察整个网络,分布在各处的资源由URI确定,而客户端的应用通过URI来获取资源的表示方式.获得这些表徵致使这些应用程序转变了其状态.随着 ...
- JavaSE中线程与并行API框架学习笔记——线程为什么会不安全?
前言:休整一个多月之后,终于开始投简历了.这段时间休息了一阵子,又病了几天,真正用来复习准备的时间其实并不多.说实话,心里不是非常有底气. 这可能是学生时代遗留的思维惯性--总想着做好万全准备才去做事 ...
- android cocos2d-x for Android安装和学习笔记(请用adt-bundle21.1或以上导入)
引用:http://weimingtom.iteye.com/blog/1483566 (20121108)注意:这篇文章用cdt编译ndk工程的内容已过时(现在可以用adt-bundle,避免配置繁 ...
- JavaSE中线程与并行API框架学习笔记1——线程是什么?
前言:虽然工作了三年,但是几乎没有使用到多线程之类的内容.这其实是工作与学习的矛盾.我们在公司上班,很多时候都只是在处理业务代码,很少接触底层技术. 可是你不可能一辈子都写业务代码,而且跳槽之后新单位 ...
- Android M Permission 学习笔记
Android应用权限简要介绍 一个Android应用默认情况下是不拥有任何权限的, 这即是说, 在默认情况下, 一个应用是没有权利去进行一些可能会造成不好影响的操作的. 这些不好的影响可能是对其它应 ...
- Android应用开发学习笔记之ContentProvider
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz ContentProvider用于为其它应用程序提供共享数据,它为不同应用程序间共享数据提供了统一的操作接口. 一. ...
- android移动开发学习笔记(二)神奇的Web API
本次分两个大方向去讲解Web Api,1.如何实现Web Api?2.如何Android端如何调用Web Api?对于Web Api是什么?有什么优缺点?为什么用WebApi而不用Webservice ...
随机推荐
- 使用实时文件夹显示ContentProvider的数据
所谓实时文件夹(即LiveFolder),是指用于显示ContentProvider提供的数据的桌面组件. ContentProvider用于向外提供数据访问的接口,一个应用程序可通过ContentP ...
- CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))
题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发 问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候 如果对于一条边 ...
- Lantern卫星接收器:为你提供免费上网服务
包括笔者在内,许多现代人的日常生活都无法离开网络,因为在网络上我们几乎可以找到任何我们需要的信息.但你是否有想过在户外无网络信号的情况下如何接收网络数据呢?一个名为Outernet Inc.的公司为我 ...
- ffmepg-nginx-nginx-rtmp-module配置脚本
把上个月写的的配置脚本贴一下: #!/bin/bash #version:-- #create by itn #dis: this is used to auto install ffmpeg+ngi ...
- SSH basics
SSH, Secure SHell, was designed and created to provide the best security when accessing another comp ...
- 三部曲一(数据结构)-1011-Sorting It All Out
每次加入一个关系都要进行拓扑排序,不过在排序过程中需要判断是否出现多个入度为0的点,如果出现了就说明不能确定大小关系.不论出不出现多个入度为0的点拓扑排序都要进行到最后来判断是否出现环,因为一旦出现环 ...
- 3、JS中的语句
1.块语句 常用于组合0~多个语句:语法:{语句1;语句2……} *没有块级作用域:如:在for循环里面定义一个自增数 i,可以在for循环外取到它跳出循环时的值,而且for循环里面新定义的数据也能取 ...
- android 检测网络是否连接,或者GPS是否可用
很多android程序在打开时,检测网络是否连接,或者GPS是否可用: 1.网络是否连接(包括Wifi和移动网络) // 是否有可用网络 private boolean isNetworkConnec ...
- Qt线程(2) QThread中使用WorkObject
一般继承QThread的WorkThread都会在重载的run()中创建临时的WorkObject,这样能确定这个WorkObject在该thread中使用 那如果这个WorkObject是个Sing ...
- Node.js高级编程读书笔记Outline
Motivation 世俗一把,看看前端的JavaScript究竟能做什么. 顺便检验一下自己的学习能力. Audience 想看偏后台的Java程序员关于前端JavaScript的认识的职业前端工程 ...