Android学习笔记:框架 - 应用程序原理1/5 - 综述

来源:互联网 发布:钢板下料软件 编辑:程序博客网 时间:2024/06/04 22:46

Android有以下重要类

    1. Activity  
    2. Service  
    3. BroadcastReceiver  
    4. ContentProvider  
    5. Intent

本文档分以下4部分

  1. Application Components
    1. Activating components: intents
    2. Shutting down components
    3. The manifest file
    4. Intent filters
  2. Activities and Tasks
    1. Affinities and new tasks
    2. Launch modes
    3. Clearing the stack
    4. Starting tasks
  3. Processes and Threads
    1. Processes
    2. Threads
    3. Remote procedure calls
    4. Thread-safe methods
  4. Component Lifecycles
    1. Activity lifecycle
    2. Service lifecycle
    3. Broadcast receiver lifecycle
    4. Processes and lifecycles

 



Android applications are written in the Java programming language. The compiled Java code — along with any data and resource files required by the application — is bundled by the aapt tool into an Android package, an archive file marked by an .apk suffix. This file is the vehicle for distributing the application and installing it on mobile devices; it's the file users download to their devices. All the code in a single .apk file is considered to be one application.

In many ways, each Android application lives in its own world:

  • By default, every application runs in its own Linux process. Android starts the process when any of the application's code needs to be executed, and shuts down the process when it's no longer needed and system resources are required by other applications.
  • Each process has its own Java virtual machine (VM), so application code runs in isolation from the code of all other applications.
  • By default, each application is assigned a unique Linux user ID. Permissions are set so that the application's files are visible only that user, only to the application itself — although there are ways to export them to other applications as well.

It's possible to arrange for two applications to share the same user ID, in which case they will be able to see each other's files. To conserve system resources, applications with the same ID can also arrange to run in the same Linux process, sharing the same VM.

Android应用程序用Java语言编写。编译过的Java代码 — 包括程序所需的任何数据和资源文件 — 被AAPT TOOL捆绑进一个Android包,一个.apk后缀标识的压缩文件通过该文件将应用程序发布并安装到移动设备上;它就是用户下载到他们设备上的文件。所有的代码都在一个简单的.apk文件里,并被当作一个应用程序

不管怎么说,每个Android应用程序都生活在它自己的世界里:

  • 默认的,所有应用程序运行在自己的Linux进程里。当任何的应用程序代码需要执行时,Android将启动这些进程,当它不再被需要而且其他应用程序需要系统资源时,Android将结束该进程。
  • 每个进程有它自己的Java虚拟机,所以应用程序代码都是独立与其他所有应用程序代码运行的。
  • 默认的,每个应用程序都被指定了一个唯一的Linux用户ID。设置了权限,使该应用程序文件仅对该用户,该应用程序自己可见 — 尽管这儿也有方法将它们导入到其他应用程序里。

两个应用程序分享相同的用户ID也是可能的,在这种情况下它们将能看到对方的文件。为节约系统资源,拥有相同ID的应用程序也可以运行在相同的Linux进程里,分享相同的虚拟机。

原创粉丝点击