00-android app之 Application Fundamentals(应用程序基本原理)

    自从工作以来一直做得都是android较为底层的东西,虽有时需要看看framework和app的东西,但是至今没有系统的学习一下android app的知识。反正闲着也是闲着,不如熟悉一下。不废话了,今天开始系统的学习app。

    也没有什么现成的资料,就看着官方文档来吧!

Application Fundamentals(应用程序基本原理)

android应用用java编写。android sdk工具把代码、数据及资源文件编译成一个apk应用程序包。可以将其安装在运行中的android设备。

一旦安装在设备中,每一个android应用程序将运行在一个单独的安全沙盒(security sandbox)中。

  • 每一个android应用程序相当于一个多用户linux系统中的用户。
  • 默认情况下,系统为每个应用程序分配一个唯一的用户ID(仅有系统和此应用使用)。系统为程序中的所有文件设置权限,因此只有同一个应用程序可以访问这些文件。
  • 每个进程有其单独的虚拟机,因此每个应用程序都独立(于其他应用)运行。
  • 默认情况下,每个app都运行在其独立的linux进程中。当任何一个app的组件需要执行的时候android就启动此程序。然后关闭其他不再需要的进程或为其他应用回收内存而关闭的进程。

按这种方式,android遵循特权最小化。那就是每个应用,默认情况下只访问它运行需要的组件;这样就组成了一个非常安全的运行环境即每个应用不能越权访问系统其它组件。

然而,应用程序仍有与其他应用共享数据或访问系统服务的方法

  • 可以让两个应用程序分享同一个linux用户ID,即他们之间可以互相访问对方的文件。为节约系统资源,拥有相同用户ID的应用程序也可以在同一个linux进程中运行并分享同一个虚拟机。
  • app可以通过申请权限去访问诸如联系人,短信,sd卡,camera,蓝牙等。所有的应用程序权限必须在安装的时候得到用户的允许。

以上介绍了android app如何存在与系统中,下面将介绍:

  • 应用程序常用的framework 核心组件
  • Androidmanifest.xml文件
  • 代码之外的一些资源文件

android有四大组件,每个组件都有独特的生命周期。

Activities
一个activity展示了一个单独的用户界面,比如:一个短信应用可能有一个activity用于显示新来短信列表,另一个acitivity用于写新邮件,其他的activity用来读邮件。所有的这些activitys组合在一起实现统一的用户体验,每个都是独立的,因此,另外不同的应用可以启动这些activity(只要短信应用程序允许)。例如,camera应用可以通过启动短信应用程序中得activity来发送照片以分享。

Services

        service是个在通过后台运行来完成长时间工作或为其他线程工作得组件,service没有界面。例如,在用户做其他事情的时候后台播放音乐,或者在不影响用户响应的情况下后台获取数据,其他的应用组件,像activity可以通过startService来启动service或者bind到service以和他交互。

Content providers
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 location your application can access. Through the content provider, other applications can query or even modify the data (if the content provider allows it). For example, the Android system provides a content provider that manages the user's contact information. As such, any application with the proper permissions can query part of the content provider (such as  ContactsContract.Data) to read and write information about a particular person.

Content providers are also useful for reading and writing data that is private to your application and not shared. For example, the Note Pad sample application uses a content provider to save notes.

A content provider is implemented as a subclass of ContentProvider and must implement a standard set of APIs that enable other applications to perform transactions. For more information, see theContent Providers developer guide.

 





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值