Android Fundamentals

API Guide - App Fundamentals



Basics

  • Android系统是’multi-user’的Linux系统,每个App是不同的’user’。
  • 每个进程都有自己的虚拟机(Virtual Machine),每个App独立于其他App运行。
  • 系统会设立一些需要权限(permission)的资源,拥有对应权限的App才能正常访问这些资源。
  • 当内存不够时,Linux系统会自动销毁不必要的进程。

App Components

  • Four Components
    Android四大组件包括:Activity, Service, Content provider, Broadcast receiver。
    组件(component)不仅可以被自身App调用,也可以由其他App的组件调用。

    App components are the essential building blocks of an Android app.
    Each component is a different point through which the system can enter your app.

    • Activities
      Activity是与用户进行交互的前台。

      An activity represents a single screen with a user interface.

    • Services
      Service是后台运行的任务,不提供UI界面。

      A service is a component that runs in the background to perform long-running operations or to perform work for remote processes.

    • Content providers

      A content provider manages a shared set of app data.

    • Broadcast receivers

      A broadcast receiver is a component that responds to system-wide broadcast announcements.

  • Activating Components
    Activiy, Service, Broadcast receiver均可以由Intent进行调用。

    • Activity: passing an Intent to startActivity() or startActivityForResult() .
    • Service: passing an Intent to startService() or bindService().
    • Broadcast receiver: passing an Intent to sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().
    • Content provider: 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). Your app must declare all its components in this file, which must be at the root of the app project directory.

  • Declare the app’s components.
  • Identify any user permissions the app requires.
  • Declare the minimum API Level
  • Declare hardware and software features, such as a camera or bluetooth.
  • API libraries the app needs to be linked against, such as the Google Maps library.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.train.eureka.intenttest">

    <!-- Declare permissions -->
    <uses-permission android:name="com.android.alarm.permission.SET_ALARM" />

    <!-- Declare app requirements -->
    <uses-feature android:name="android.hardware.camera.any"
                  android:required="true" />
    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <!-- Declare components -->
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">

        <!-- Declare components capabilities -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

App Resource

在res目录下,包含着App需要的各种资源文件,包括drawable, layout, menu, mipmap, values。

An Android app 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 app.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值