Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
10_组件-数据存储
Search
powerhope
August 11, 2016
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
10_组件-数据存储
App Inventor移动应用开发
powerhope
August 11, 2016
More Decks by powerhope
See All by powerhope
1_App Inventor初步
powerhope
0
290
2_1_HelloPurr
powerhope
0
150
2_2_8-Ball(魔术8球)
powerhope
2
170
3_App Inventor编程基础
powerhope
0
140
4_组件-用户界面
powerhope
0
190
5_组件-界面布局
powerhope
0
180
6_组件-多媒体
powerhope
0
140
7_组件-绘图动画
powerhope
0
160
8_组件-传感器
powerhope
0
160
Featured
See All Featured
Everyday Curiosity
cassininazir
0
310
Rails Girls Zürich Keynote
gr2m
96
14k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
270
A designer walks into a library…
pauljervisheath
211
25k
A Soul's Torment
seathinner
7
3.5k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
810
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
230
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
400
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
230
Transcript
College of Mathematics and Computer Science, Hunan Normal University 瞿绍军
湖南师范大学数学与计算机科学学院
College of Mathematics and Computer Science, Hunan Normal University
College of Mathematics and Computer Science, Hunan Normal University
文件管理器是用于存储和检索文件的非可视组件, 可以在设备上实现文件的读或写。默认情况下,会 将文件写入与应用有关的私有数据目录中。在伴侣 中,为了便于调试,将文件写在 /sdcard/AppInventor/data文件夹内。如果文件 的路径以“/”开始,则文件的位置是相对于/sdcard 而言,例如,将文件写入/myFile.txt,就是将文件 写入/sdcard/myFile.txt。 文件管理器File
College of Mathematics and Computer Science, Hunan Normal University 文件管理器File
College of Mathematics and Computer Science, Hunan Normal University
追加内容。将文字添加到现有文件的尾部,如果文 件不存在,则创建新文件。关于文件的写操作,请 参见下面的“保存文件”方法。 删除。从设备存储器中删除一个已有文件。文件名 前加“/”表示删除SD卡上的指定文件,例如删除文 件/myFile.txt,则将删除文件 /sdcard/myFile.txt;如果文件名前没有“/”,将 删除应用私有目录中的文件;如果文件名前有 “//”,则被视为错误,因为资源性文件不能被删 除。 文件管理器File
College of Mathematics and Computer Science, Hunan Normal University
读取文件。从设备存储器中读取文件内容(文字)。 文件名前加“/”表示从SD卡中读取指定文件,例如 读取文件/myFile.txt,就是读取文件 /sdcard/myFile.txt;文件名前加“//”表示从应 用(同时也是AI伴侣)的资源包中读取文件;如果文 件名前没有“/”,则从应用的私有目录(应用包)及伴 侣目录(/sdcard/AppInventor/data)中读取文件 。 文件管理器File
College of Mathematics and Computer Science, Hunan Normal University
保存文件。将文字保存为文件。如果文件名前加 “/”,则将文件保存到SD卡,例如写文件 /myFile.txt,就是写文件/sdcard/myFile.txt; 如果文件名前没有“/”,则将文件写入应用的私有 数据目录中,手机中的其他应用将无法访问这些目 录,但AI伴侣是个例外,为了便于调试,将文件写 入/sdcard/AppInventor/data文件夹。需要注意 的是,如果文件已经存在,则本方法将覆盖原有文 件。如果想要在原有文件中添加内容而不是覆盖, 可以选用追加内容方法。 文件管理器File
College of Mathematics and Computer Science, Hunan Normal University 例:记事本
College of Mathematics and Computer Science, Hunan Normal University 例:记事本
College of Mathematics and Computer Science, Hunan Normal University 例:记事本
College of Mathematics and Computer Science, Hunan Normal University 例:记事本
College of Mathematics and Computer Science, Hunan Normal University 例:记事本
College of Mathematics and Computer Science, Hunan Normal University
微数据库是一个非可视组件,用来保存应用中的数 据。 用App Inventor创建的应用,在每次运行时都会进 行初始化:如果应用中设定了变量的值,当用户退 出应用再重新运行应用时,那些被设定过的变量值 将不复存在;而微数据库则为应用提供了一种永久 的数据存储,即,每次应用启动时,都可以获得那 些保存过的数据。比如游戏中保存的最高得分,每 次游戏中都可以读取到它。 微数据库TinyDB
College of Mathematics and Computer Science, Hunan Normal University
数据项是以字符串的方式保存在标签的名下,即, 需要为保存的每一项数据设定一个专用的标签,以 便之后用这个标签来读取已经保存的数据。 每个应用中只有一个数据存储区,即便在应用中添 加了多个微数据库组件,它们也将使用同一个存储 区。如果想使用不同的存储区,需要使用不同的密 钥。同样,每个应用拥有独立的存储区,虽然在多 屏应用中能够在不同屏幕之间共享数据,但同一部 手机上的不同应用之间却无法通过微数据库来传递 数据。 微数据库TinyDB
College of Mathematics and Computer Science, Hunan Normal University
在使用AI伴侣开发应用时,使用该伴侣的所有应用 都将共用一个微数据库,而一旦应用打包之后,数 据的共享将不复存在。但在开发过程中,每次创建 新项目时,都需留心清空微数据库。 微数据库TinyDB
College of Mathematics and Computer Science, Hunan Normal University 微数据库TinyDB
College of Mathematics and Computer Science, Hunan Normal University
清除所有数据(ClearAll):清空整个微数据库中 的数据存储。 清除标签数据(ClearTag):清除指定标签下的数 据。 获取标签数据(GetTags):返回该数据存储区内 全部标签列表。 获取数值(GetValue):通过给定的标签检索存储 的数据,如果不存在此标签,则返回设定的字符串 。 保存数值(StoreValue):在指定的标签下保存给 定的值,每当应用重新启动时,数据依然存储在手 机中。
College of Mathematics and Computer Science, Hunan Normal University 联系人管理器
College of Mathematics and Computer Science, Hunan Normal University
personinformation为一维列表,用来临时存放用 户每次输入的联系人信息(姓名、办公电话和手机 号码)。contacts为二维列表,存放所有的联系人 信息。contactslist以一维列表形式存放contacts 中所有内容,供列表选择框使用。 联系人管理器
College of Mathematics and Computer Science, Hunan Normal University 联系人管理器
College of Mathematics and Computer Science, Hunan Normal University
“contactnumber”过程实现将二维列表 contacts中的内容转换成一维列表形式。 联系人管理器
College of Mathematics and Computer Science, Hunan Normal University
屏幕初始化事件,当屏幕初始化的时候,首先从微 数据库中取出联系人信息,并赋值给全局变量 contacts,这样才能保证下次使用应用时前面录入 的数据还在。 联系人管理器
College of Mathematics and Computer Science, Hunan Normal University 联系人管理器
College of Mathematics and Computer Science, Hunan Normal University 联系人管理器
College of Mathematics and Computer Science, Hunan Normal University
不可视组件,通过与Web服务通信来保存并读取信 息。 可参见创建定制的网络微数据库服务创建网络微数 据库( http://app.gzjkw.net/reference/other/tinywe bdb.html) 网络微数据库TinyWebDB
College of Mathematics and Computer Science, Hunan Normal University
得数值(GotValue):表示调 用获取数值的服务请求已经成 功。 数值存储完毕(ValueStored ):表示存储数据的服务器请 求已经成功。 发生Web服务故障( WebServiceError):表示与 Web服务之间的通信出现错误 。 网络微数据库
College of Mathematics and Computer Science, Hunan Normal University
获取数值(GetValue):向Web服务发出获取存储 在指定标签下的数据请求,如果没有值存储在标签 下,Web服务必须决定如何返回。该组件接收任何 返回。 保存数值(StoreValue):向Web服务发出将指定 的标签下的数值存储的请求。 网络微数据库
College of Mathematics and Computer Science, Hunan Normal University 网络微数据库
College of Mathematics and Computer Science, Hunan Normal University 网络微数据库
College of Mathematics and Computer Science, Hunan Normal University
与谷歌融合图表(Google Fusion Tables)通信 ,融合图表可让用户存储、共享、查询和可视化数 据表;该组件允许您查询,创建和修改这些表。 该组件使用的是Fusion Tables API V1.0( https://developers.google.com/fusiontables/ docs/v1/getting_started) 融合图表控制组件FusionTablesControl
College of Mathematics and Computer Science, Hunan Normal University
应用程序使用融合图表必须使用谷歌的服务器进行 身份验证。有两种方法可以实现:第一种方法是使 用获得的API密钥(开发人员)。使用这种方法,最 终用户也必须登录访问融合图表。 第二种方法是使用身份验证服务。用这种方法创建 凭证和一个特殊的“服务帐户的电子邮件地址”,允 许最终用户不需要登录使用你的融合图表,您的服 务帐户验证所有访问。 融合图表控制组件FusionTablesControl
College of Mathematics and Computer Science, Hunan Normal University
实验9. 制作课程表。 实验10. 制作记事本。 实验11. 给联系人管理器增加修改联系人和删除联 系人功能。 实验