Fragment工作过程

常见类的介绍

  • ActivityThread : 入口类
  • Instrumentation : ActivityThread 的得力助手,帮助 ActivityThread 触发 Activity 的生命周期
  • MainActivity : 就是上文提到例子中的 MainActivity 类,继承自 Activity
  • HostCallbacks : Activity 的内部类,继承自 FragmentHostCallback
Read More

ContentProvider

概述

ContentProvider是一种数据共享型组件,可以在应用之间共享数据。所以与BroadcastReceiver一样,其可以脱离Activity实现。在实现ContentProvider时,
需要继承ContentProvider抽象类,然后在AndroidManifest.xml中注册类名和ContentProvider的域名。同样的,不需要重写onCreat()方法,而是实现CRUD操作,
所以ContentProvider没有启动和停止的概念,更像是一个系统级的监听器。与前三个组件不同的是,ContentProvider并没有使用intent,
而是使用URI来判定能否为ContentResolver提供数据共享。

关于ContentProvider,用来提供其他地方(包括其他App)调用的一种全局(系统级)方式。有了ContentProvider,我们就能方便的调用相册的东西、
进行文件选择,在我们自己的App中,也可以提供一个数据中心。

当数据量比较大的时候,继续用Parcel做容器效率会比较低,因此它还使用了匿名共享内存的方式。

但是有一个问题是,ContentProvider的提供者进程不再存活时,其他进程通过Provider读一个非 常简单的数据时,都需要先把提供者进程启动起来(除非
指定multiprocess=true),这对用户是 相当不友好的。又因为其是间接通过db进行数据操作,所以效率也远不如直接操作db。因此在用户app中,
不是很建议经常使用ContentProvider。不过对于系统级的app,它统一了数据操作的规范,利是远大于弊的。

在很多开源库中,也运用了ContentProvider的特性来进行初始化。

Read More

ContentProvider工作过程

概要

ContentProvider主要用来给不同应用提供数据,当其所在进程启动时,ContentProvider会同时启动并发布到AMS中。

当android:multiprocess为true时,ContentProvider为多实例。

其提供了query、update、delete、insert等接口,方便我们进行数据操作。

启动流程

我们要使用ContentProvider,需要通过getContentResolver(),实际是ApplicationContentResolver对象。

我们从query方法入手

Read More

AndroidManifest描述文件

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?xml version="1.0" encoding="uft-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/red/android"
package="com.example.android"
android:versionCode="1"
android:versionName="1.0">
<uses-permission />
<permission />
<permission-tree /> 权限配置
<permission-group />

<instrumentation android:functionalTest=["true" | "false"]
android:handleProfiling=["true" | "false"]
android:icon="drawable resource"
android:label="string resource"
android:name="string"
android:targetPackage="string" />
<uses-sdk />
<uses-configuration />
<uses-feature /> 环境配置
<supports-screens />
<compatible-screens />
<supports-gl-texture />

应用基本配置
<application android:allowTaskReparenting=["true" | "false"]
android:allowBackup=["true" | "false"]
android:backupAgent="string"
android:debuggable=["true" | "false"]
android:description="string resource"
android:enabled=["true" | "false"]
android:hasCode=["true" | "false"]
android:hardwareAccelerated=["true" | "false"]
android:icon="drawable resource"
android:killAfterRestore=["true" | "false"]
android:largeHeap=["true" | "false"]
android:label="string resource"
android:logo="drawable resource"
android:manageSpaceActivity="string"
android:name="string"
android:permission="string"
android:persistent=["true" | "false"]
android:process="string"
android:restoreAnyVersion=["true" | "false"]
android:requiredAccountType="string"
android:restrictedAccountType="string"
android:supportsRtl=["true" | "false"]
android:taskAffinity="string"
android:testOnly=["true" | "false"]
android:theme="resource or theme"
android:uiOptions=["none" | "splitActionBarWhenNarrow"]
android:vmSafeMode=["true" | "false"] >
//界面组件配置
<activity android:allowTaskReparenting=["true" | "false"]
android:alwaysRetainTaskState=["true" | "false"]
android:clearTaskOnLaunch=["true" | "false"]
android:configChanges=["mcc", "mnc", "locale",
"touchscreen", "keyboard", "keyboardHidden",
"navigation", "screenLayout", "fontScale", "uiMode",
"orientation", "screenSize", "smallestScreenSize"]
android:enabled=["true" | "false"]
android:excludeFromRecents=["true" | "false"]
android:exported=["true" | "false"]
android:finishOnTaskLaunch=["true" | "false"]
android:hardwareAccelerated=["true" | "false"]
android:icon="drawable resource"
android:label="string resource"
android:launchMode=["multiple" | "singleTop" |
"singleTask" | "singleInstance"]
android:multiprocess=["true" | "false"]
android:name="string"
android:noHistory=["true" | "false"]
android:parentActivityName="string"
android:permission="string"
android:process="string"
android:screenOrientation=["unspecified" | "behind" |
"landscape" | "portrait" |
"reverseLandscape" | "reversePortrait" |
"sensorLandscape" | "sensorPortrait" |
"userLandscape" | "userPortrait" |
"sensor" | "fullSensor" | "nosensor" |
"user" | "fullUser" | "locked"]
android:stateNotNeeded=["true" | "false"]
android:taskAffinity="string"
android:theme="resource or theme"
android:uiOptions=["none" | "splitActionBarWhenNarrow"]
android:windowSoftInputMode=["stateUnspecified",
"stateUnchanged", "stateHidden",
"stateAlwaysHidden", "stateVisible",
"stateAlwaysVisible", "adjustUnspecified",
"adjustResize", "adjustPan"] >
. . .
</activity>

<activity>
<intent-filter>
<action />
<category />
<data />
</intent-filter>
<meta-data />
</activity>

<activity-alias>
<intent-filter> . . . </intent-filter>
<meta-data />
</activity-alias>
<service>
<intent-filter> . . . </intent-filter>
<meta-data/> 服务组件配置
</service>
<receiver>
<intent-filter> . . . </intent-filter> 触发器组件配置
<meta-data />
</receiver>
数据源组件配置



<provider android:authorities="list"
android:enabled=["true" | "false"]
android:exported=["true" | "false"]
android:grantUriPermissions=["true" | "false"]
android:icon="drawable resource"
android:initOrder="integer"
android:label="string resource"
android:multiprocess=["true" | "false"]
android:name="string"
android:permission="string"
android:process="string"
android:readPermission="string"
android:syncable=["true" | "false"]
android:writePermission="string" >
. . .
</provider>
-------------------------------------------------------------------------------------------------------------------------------------------
<uses-library /> 依赖库配置
-------------------------------------------------------------------------------------------------------------------------------------------
</application>
</manifest>

manifest标签

Read More