udacity android 实践笔记: lesson 4 part a

2024-04-11 14:58

本文主要是介绍udacity android 实践笔记: lesson 4 part a,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

udacity android 实践笔记: lesson 4 part a


作者:干货店打杂的 /titer1 /Archimedes
出处:https://code.csdn.net/titer1
联系:1307316一九六八(短信最佳)
声明:本文采用以下协议进行授权: 自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0 ,转载请注明作者及出处。
tips:https://code.csdn.net/titer1/pat_aha/blob/master/Markdown/android/


序言

this is weekend time
last time ,we have learn form the video
and now ,we are run the code directly.
let us go.thanks jackson
版本变化的
rs232 uart txd rxd clk 115200 10k
usb at least 5 ,传输类型1.0 fullspeded <10M2.0 highspeedd, 30M? 720p 20fpsprinter more high than uvcusb mass storage ..dirver-inside3.0 >100Mi2c2 line .clk data400k bps,命令
是否是 fake data,看看 数据里面 有没有 traped in weather station,就知道当前情况了

其他 四大组件

service
broad
content provider
activity

4.01 life cycle



以上介绍了 声明周期

!! 动手笔记 生命周期

看activity的生命周期,就是
看 mainActivity的logcat,非常清楚

操作布凑

进入mainActivity –> detail Activity –>回到 mainActivity

还有 Main Activity –> seting –>切回

为什么能够看到如上的提示,根本原因是有代码logcat,
所有的activity life cycle hanlders

overviw 图


- contract
- db builder
- content provider 四大组件之一

4.02 第四章最基础的代码框架


- 完整的测试框架
- 添加了 location weather的contract
- 添加了 location weather相关的 sql builder

4.03 定义 数据库表项 for location

contract解释

/*** Defines table and column names for the weather database.*/

就是定义 表格内容

这里的更新就是 增加了
location table 的列内容定义

4.04 完善 location database

- 目标 测试 weather 数据库 创建 /插入

在数据库初始化代码处,
也就是 weatherDbHelper的位置,
仿照 weather database的创建,
添加以下代码

public class WeatherDbHelper extends SQLiteOpenHelper {static final String DATABASE_NAME = "weather.db";@Overridepublic void onCreate(SQLiteDatabase sqLiteDatabase) {final String SQL_CREATE_LOCATION_TABLE = "CREATE TABLE " + LocationEntry.TABLE_NAME + " (" +LocationEntry._ID + " INTEGER PRIMARY KEY," +LocationEntry.COLUMN_LOCATION_SETTING + " TEXT UNIQUE NOT NULL, " +LocationEntry.COLUMN_CITY_NAME + " TEXT NOT NULL, " +LocationEntry.COLUMN_COORD_LAT + " REAL NOT NULL, " +LocationEntry.COLUMN_COORD_LONG + " REAL NOT NULL " +" );";
...sqLiteDatabase.execSQL(SQL_CREATE_LOCATION_TABLE);//新添加的sqLiteDatabase.execSQL(SQL_CREATE_WEATHER_TABLE);

使能数据库创建测试程序 testCreateDb

程序介绍

        Students: Uncomment this test once you've written the code to create the Locationtable.  Note that you will have to have chosen the same column names that I did in my solution for this test to compile, so if you haven't yet done that, this isa good time to change your column names to match mine.Note that this only tests that the Location table has the correct columns, since wegive you the code for the weather table.  This test does not look at the

使能 test utilites

/*Students: You can uncomment this helper function once you have finished creating theLocationEntry part of the WeatherContract.*/static ContentValues createNorthPoleLocationValues() {// Create a new map of values, where column names are the keysContentValues testValues = new ContentValues();testValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, TEST_LOCATION);testValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, "North Pole");testValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, 64.7488);testValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, -147.353);return testValues;}/*Students: You can uncomment this function once you have finished creating theLocationEntry part of the WeatherContract as well as the WeatherDbHelper.*/static long insertNorthPoleLocationValues(Context context) {// insert our test records into the databaseWeatherDbHelper dbHelper = new WeatherDbHelper(context);//我的认识,这里会创建一个表SQLiteDatabase db = dbHelper.getWritableDatabase();ContentValues testValues = TestUtilities.createNorthPoleLocationValues();long locationRowId;locationRowId = db.insert(WeatherContract.LocationEntry.TABLE_NAME, null, testValues);
//这里将测试表的插入// Verify we got a row back.assertTrue("Error: Failure to insert North Pole Location Values", locationRowId != -1);return locationRowId;}

上面三处文件更新

4.05 test Location Table

这里 近一处 更新

可以从 注释里面进一步完善本小节内容

下面小节的内容将会被充实代码

/*Students:  Here is where you will build code to test that we can insert and query the location database. We've done a lot of work for you.  You'll want to look in TestUtilitiewhere you can uncomment out the "createNorthPoleLocationValues" function.  You can also make use of the ValidateCurrentRecord function from within TestUtilities.*/public void testLocationTable() {// First step: Get reference to writable database// Create ContentValues of what you want to insert// (you can use the createNorthPoleLocationValues if you wish)// Insert ContentValues into database and get a row ID back// Query the database and receive a Cursor back// Move the cursor to a valid database row// Validate data in resulting Cursor with the original ContentValues// (you can use the validateCurrentRecord function in TestUtilities to validate the// query if you like)// Finally, close the cursor and database}```### 6步 测试table(insert/quiery ...)
所有更新的代码在此
``` javapublic void testLocationTable() {// First step: Get reference to writable database// If there's an error in those massive SQL table creation Strings,// errors will be thrown here when you try to get a writable database.WeatherDbHelper dbHelper = new WeatherDbHelper(mContext);SQLiteDatabase db = dbHelper.getWritableDatabase();// Second Step: Create ContentValues of what you want to insert// (you can use the createNorthPoleLocationValues if you wish)ContentValues testValues = TestUtilities.createNorthPoleLocationValues();// Third Step: Insert ContentValues into database and get a row ID backlong locationRowId;locationRowId = db.insert(WeatherContract.LocationEntry.TABLE_NAME, null, testValues);// Verify we got a row back.assertTrue(locationRowId != -1);// Data's inserted.  IN THEORY.  Now pull some out to stare at it and verify it made// the round trip.// Fourth Step: Query the database and receive a Cursor back// A cursor is your primary interface to the query results.Cursor cursor = db.query(WeatherContract.LocationEntry.TABLE_NAME,  // Table to Querynull, // all columnsnull, // Columns for the "where" clausenull, // Values for the "where" clausenull, // columns to group bynull, // columns to filter by row groupsnull // sort order);// Move the cursor to a valid database row and check to see if we got any records back// from the queryassertTrue( "Error: No Records returned from location query", cursor.moveToFirst() );// Fifth Step: Validate data in resulting Cursor with the original ContentValues// (you can use the validateCurrentRecord function in TestUtilities to validate the// query if you like)TestUtilities.validateCurrentRecord("Error: Location Query Validation Failed",cursor, testValues);// Move the cursor to demonstrate that there is only one record in the databaseassertFalse( "Error: More than one record returned from location query",cursor.moveToNext() );// Sixth Step: Close Cursor and Databasecursor.close();db.close();}<div class="se-preview-section-delimiter"></div>

!! todo 效果截图

这处 等待网络 联通后,应该有 具体的效果图展示,
初步看到这里有若干的assert

//运行方法:lesson 4a 28 - SQLiteOpenHelper and Sunshine Database.mp4中

我把 问题的环境 运行方法 已经 整理,待后期更新

4.06 test weather table

和上面一样,修改的只有 testDb.java

编辑器里面 有 主题切换,可以后界面颜色 ,字体,保护眼睛,你懂的<div class="se-preview-section-delimiter"></div>
  • 不仅仅像上面 重新 写了一个 test*****talbe的函数,
  • 在testWeatherTalbe程序中,先调用了 testLoactionTalbe的代码,
    该代码被封装起来为insertLocation,其实内容就是 testLocationTable

  • 函数的返回值是 对应项目 query后的rowid 。

两者衔接的代码如下,

        long locationRowId = insertLocation();// Second Step (Weather): Create weather valuesContentValues weatherValues = TestUtilities.createWeatherValues(locationRowId);//*.insert//*.query<div class="se-preview-section-delimiter"></div>
至于是否起到 外键的作用,待证明

小憩时间

至此,逻辑正确的话,两个数据表格都测到测试
未来目标是 4.24..还有很多。

- 给出初步的 创建 weather表的表框架
- 创建 location 表
- 填充 test location
- 填充 test weather location (insert query …,调用了 testlocation的结果)

一句话 ,期中 4.06是一个 小的 里程碑

这篇关于udacity android 实践笔记: lesson 4 part a的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/894402

相关文章

Android中Dialog的使用详解

《Android中Dialog的使用详解》Dialog(对话框)是Android中常用的UI组件,用于临时显示重要信息或获取用户输入,本文给大家介绍Android中Dialog的使用,感兴趣的朋友一起... 目录android中Dialog的使用详解1. 基本Dialog类型1.1 AlertDialog(

Spring Boot 配置文件之类型、加载顺序与最佳实践记录

《SpringBoot配置文件之类型、加载顺序与最佳实践记录》SpringBoot的配置文件是灵活且强大的工具,通过合理的配置管理,可以让应用开发和部署更加高效,无论是简单的属性配置,还是复杂... 目录Spring Boot 配置文件详解一、Spring Boot 配置文件类型1.1 applicatio

tomcat多实例部署的项目实践

《tomcat多实例部署的项目实践》Tomcat多实例是指在一台设备上运行多个Tomcat服务,这些Tomcat相互独立,本文主要介绍了tomcat多实例部署的项目实践,具有一定的参考价值,感兴趣的可... 目录1.创建项目目录,测试文China编程件2js.创建实例的安装目录3.准备实例的配置文件4.编辑实例的

Python 中的异步与同步深度解析(实践记录)

《Python中的异步与同步深度解析(实践记录)》在Python编程世界里,异步和同步的概念是理解程序执行流程和性能优化的关键,这篇文章将带你深入了解它们的差异,以及阻塞和非阻塞的特性,同时通过实际... 目录python中的异步与同步:深度解析与实践异步与同步的定义异步同步阻塞与非阻塞的概念阻塞非阻塞同步

Python Dash框架在数据可视化仪表板中的应用与实践记录

《PythonDash框架在数据可视化仪表板中的应用与实践记录》Python的PlotlyDash库提供了一种简便且强大的方式来构建和展示互动式数据仪表板,本篇文章将深入探讨如何使用Dash设计一... 目录python Dash框架在数据可视化仪表板中的应用与实践1. 什么是Plotly Dash?1.1

Android Kotlin 高阶函数详解及其在协程中的应用小结

《AndroidKotlin高阶函数详解及其在协程中的应用小结》高阶函数是Kotlin中的一个重要特性,它能够将函数作为一等公民(First-ClassCitizen),使得代码更加简洁、灵活和可... 目录1. 引言2. 什么是高阶函数?3. 高阶函数的基础用法3.1 传递函数作为参数3.2 Lambda

springboot集成Deepseek4j的项目实践

《springboot集成Deepseek4j的项目实践》本文主要介绍了springboot集成Deepseek4j的项目实践,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价... 目录Deepseek4j快速开始Maven 依js赖基础配置基础使用示例1. 流式返回示例2. 进阶

Android自定义Scrollbar的两种实现方式

《Android自定义Scrollbar的两种实现方式》本文介绍两种实现自定义滚动条的方法,分别通过ItemDecoration方案和独立View方案实现滚动条定制化,文章通过代码示例讲解的非常详细,... 目录方案一:ItemDecoration实现(推荐用于RecyclerView)实现原理完整代码实现

Android App安装列表获取方法(实践方案)

《AndroidApp安装列表获取方法(实践方案)》文章介绍了Android11及以上版本获取应用列表的方案调整,包括权限配置、白名单配置和action配置三种方式,并提供了相应的Java和Kotl... 目录前言实现方案         方案概述一、 androidManifest 三种配置方式

Spring Boot中定时任务Cron表达式的终极指南最佳实践记录

《SpringBoot中定时任务Cron表达式的终极指南最佳实践记录》本文详细介绍了SpringBoot中定时任务的实现方法,特别是Cron表达式的使用技巧和高级用法,从基础语法到复杂场景,从快速启... 目录一、Cron表达式基础1.1 Cron表达式结构1.2 核心语法规则二、Spring Boot中定