App Fundamentals

Application Fundamentals

Android apps are written in the java programming language. The Android SDK tools compile our code --- along with any data and resource files --- into an APK: an Android package, which is an archive file with an .apk suffix. One APK file contains all the contents of an Android app and is the file that Android-powered devices use to install the app.

Once installed on a device,each Android app lives in its own security sandbox:

a>The Android operating system is a multi-user linux system in which each app is a different user

b>By default,the system assigns each app a unique Linux system user ID(the ID is uses only by the system and is unknown to the app).The system sets permissions for all the files in an app so that only the user ID assigned to that app can access them.

c>Each process has its own virtual machine(VM),so an app's code runs in isolation from other apps.

d>By default, every app runs in its own linux process.Android starts the process when any of the app's components need to be executed, then shuts down the process when it's no longer needed or when the system must recover memory for other apps.

In this way, the Android system implements the principle of least privilege. This creates a very secure environment in which an app cannot access parts of the system for which it is not given permission.

However, there are ways for an app to share data with other apps and for an app to access system services:

a>It's possible to arrange for two apps to share the same Linux user ID, in which case they are able to access each other's files. To conserve system resources,apps with the same user ID can also arrange to run in the same Linux process and share the same VM(the apps must also be signed with the same certificate).

b>An app can request permission to access device data such as the user's contacts, SMS messages, the mountable storage(SD card), camera, Bluetooth, and more. All app permissions must be granted by the user at install time.


App Components

activities:

An activity represents a single screen with a user interface.

Services:

A service is a component that runs in the background to perform long-running operations or to perform work for remote processes.And A service does not provide a user interface.

Content providers:

A content provider manages a shared set of app data. We can store the data in the file system,an SQLite database, on the web, or any other persistent storage location our app can access.Through the content provider, other apps can query or even modify the data(if the content provider allows it).

Content providers are also useful for reading and writing data that is private to our app and not shared.

Broadcast receivers:

A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate form the system. Apps can also initiate broadcasts.Although broadcast receivers don't display a user interface, they may create a status bar notification to alert the user when a broadcast event occurs. Many commonly, a broadcast receiver is just a "gateway" to other components and is intended to do a very minimal amount of work.

A unique aspect of the Android system design is that any app can start another app's component.

When the system starts a component, it starts the process for that app (if it's not already running) and instantiates the classes needed for the component. Therefore, unlike apps on most other systems, Android apps don't have a single entry point (there's no main() function).

Because the system runs each app in a separate process with file permissions that restrict access to other apps, our app cannot directly activate a component from another app. The Android system, however, can. So, to activate a component in another app, we must deliver a message to the system that specifies our intent to start a particular component. The system then activates the component for us.

Activating Components

Three of the four component type --- activities, services,and broadcast receivers --- are activated by an asynchronous message called an intent.

An intent is created with an Intent object, which defines a message to activate either a specific component or a specific type of component --- an intent can be either explicit or implicit, respectively.

For activities and services, an intent defines the action to perform (for example, to "view" or "send" something) and many specify the URI of the data to act on (among other things that component being started might need to know).

For broadcast receivers, the intent simply defines the announcement being broadcast.

The other component type, content provider, is not activated by intents. Rather, it is activated when targeted by a request from a ContentResolver.

There are separate methods for activating each type of component:

a>We 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).

b>We can start a service (or give new instructions to an ongoing service) by passing an intent to startService(). Or we can bind to the service by passing an intent to bindService().

c>We can initiate a broadcast by passing an intent to methods like sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().

d>We can perform a query to a content provider by calling query() on a ContentResolver.


The Manifest File

Before the Android system can start an app component, the system must know that the component exists by reading the app's AndroidManifest.xml file (the "manifest" file). Our app must declare all its components in this file, which must be at the root of the app project directory.

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

a>Identify any user permissions the app requires.

b>Declare the minimum API Level required, based on which APIs the app uses.

c>Declare hardware and software features used or required by the app.

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

e>And more.

Declaring components

The primary task of the manifest is to inform the system about the app's components.

We must declare all app components this way:

a> <activity> elements for activities

b> <service> elements for services

c> <receiver> elements for broadcast receivers

d> <provider> elements for content provider

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().

Declaring component capabilities

We can use an Intent to start activities, services, and broadcast receivers.

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

When we declare an activity in our app's manifest, we can optionally include intent filters that declare the capabilities of the activity so it can respond to intents from other apps. We can declare an intent filter for our component by adding an <intent-filter> element as a child of the component's declaration element.

Declaring app 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 our app from being installed on devices the lack features needed by our app, it's important that we clearly define a profile for the types of devices our app supports by declaring device and software requirements in our manifest file. Most of these declarations are information only and the system does not read them, but external services such as Google Play do read them in order to provide filtering for users when they search for apps from their device.

App Resources

An Android app is composed of more than just code --- it requires resources that are separate from the source code.

For every resource that we include in our Android project, the SDK build tools define a unique integer ID, which we can use to reference the resource from our app code or from other resources defined in XML.

One of the most important aspect of providing resources separate from our source code is the ability for we to provide alternative resources for different device configurations.

Android supports many different qualifiers for our alternative resources. The qualifier is a short string that we include in the name of our resource directories in order to define the device configuration for which those resources should be used. As another example, we should often create different layouts for our activities, depending on the device's screen orientation and size.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测(Object Detection)是计算机视觉领域的一个核心问题,其主要任务是找出图像中所有感兴趣的目标(物体),并确定它们的类别和位置。以下是对目标检测的详细阐述: 一、基本概念 目标检测的任务是解决“在哪里?是什么?”的问题,即定位出图像中目标的位置并识别出目标的类别。由于各类物体具有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具挑战性的任务之一。 二、核心问题 目标检测涉及以下几个核心问题: 分类问题:判断图像中的目标属于哪个类别。 定位问题:确定目标在图像中的具体位置。 大小问题:目标可能具有不同的大小。 形状问题:目标可能具有不同的形状。 三、算法分类 基于深度学习的目标检测算法主要分为两大类: Two-stage算法:先进行区域生成(Region Proposal),生成有可能包含待检物体的预选框(Region Proposal),再通过卷积神经网络进行样本分类。常见的Two-stage算法包括R-CNN、Fast R-CNN、Faster R-CNN等。 One-stage算法:不用生成区域提议,直接在网络中提取特征来预测物体分类和位置。常见的One-stage算法包括YOLO系列(YOLOv1、YOLOv2、YOLOv3、YOLOv4、YOLOv5等)、SSD和RetinaNet等。 四、算法原理 以YOLO系列为例,YOLO将目标检测视为回归问题,将输入图像一次性划分为多个区域,直接在输出层预测边界框和类别概率。YOLO采用卷积网络来提取特征,使用全连接层来得到预测值。其网络结构通常包含多个卷积层和全连接层,通过卷积层提取图像特征,通过全连接层输出预测结果。 五、应用领域 目标检测技术已经广泛应用于各个领域,为人们的生活带来了极大的便利。以下是一些主要的应用领域: 安全监控:在商场、银行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值