未分类

Android第一课——初识Android

Android四大组件

Activity活动

  • 包含应用所有看得见的东西

    Service服务

  • 无法看到,在后台运行,退出应用仍可继续运行

    Broadcast Receiver广播接收器

  • 允许应用接收来自各处的消息,如电话、短信等。应用也可发出自己的广播消息。

    Content Provider内容提供器

  • 程序间共享数据的方法

Android工程的结构

image
image

AndroidManifest.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!--注意application标签要写在所有其他标签之后-->
<activity android:name=".HelloWorldActivity"
android:label="Title">
<!--程序包名可省略-->
<intent-filter>
<!--在intent-fliter中指示该应用可以处理的intent类型-->
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!--action和category两行表示该活动为主活动-->
<!--可选用data标签指定当前活动能响应的数据类型-->

</intent-filter>
</activity>

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

build.gradle

~\build.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
buildscript { 
repositories {
jcenter()//jcenter是一个代码托管仓库,有这一行就可以引用上面的开源项目
}
dependencies {
classpath 'com.android.tools.build: gradle:2.2.0'
}
}
allprojects {
repositories {
jcenter()
}
}

~\app\src\build.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
apply plugin:'com.android.application' //表示这是应用程序模块
//com.android.library表示库模块

android {//android闭包
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.example.helloworld"
//包名
minSdkVersion 15
//最低兼容版本
targetSdkVersion 24
//做过充分测试的版本
versionCode 1//版本号
versionName "1.0"//版本名
}
buildTypes {
release {
minifyEnabled false//是否对项目代码混淆
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir:'libs', include:['*.jar']) //本地依赖声明
compile 'com.android.support:appcompat-v7:24.2.1' //远程依赖库
//com~support是域名
//app~v7是组名
//24.2.1是版本号
//库依赖:compile project(':libraryxxx')
testCompile 'junit:junit:4.12'//测试用例库
}
分享到