udacity android 實踐筆記: lesson 4 part a

來源:互聯網
上載者:User

標籤:android   udacity課程   

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 timelast time ,we have learn form the videoand now ,we are run the code directly.let us go.thanks jackson版本變化的rs232 uart txd rxd clk 115200 10kusb     at least 5 ,傳輸類型    1.0 fullspeded <10M    2.0 highspeedd, 30M? 720p 20fps        printer more high than uvc        usb mass storage ..dirver-inside    3.0 >100Mi2c    2 line .clk data    400k 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 locationcontract解釋
/** * 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";    @Override    public 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 Location        table.  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 is        a good time to change your column names to match mine.        Note that this only tests that the Location table has the correct columns, since we        give 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 the        LocationEntry part of the WeatherContract.     */    static ContentValues createNorthPoleLocationValues() {        // Create a new map of values, where column names are the keys        ContentValues 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 the        LocationEntry part of the WeatherContract as well as the WeatherDbHelper.     */    static long insertNorthPoleLocationValues(Context context) {        // insert our test records into the database        WeatherDbHelper 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 TestUtilitie        where 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 ...)所有更新的代碼在此``` java public 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 back        long 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 Query                null, // all columns                null, // Columns for the "where" clause                null, // Values for the "where" clause                null, // columns to group by                null, // columns to filter by row groups                null // sort order        );        // Move the cursor to a valid database row and check to see if we got any records back        // from the query        assertTrue( "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 database        assertFalse( "Error: More than one record returned from location query",                cursor.moveToNext() );        // Sixth Step: Close Cursor and Database        cursor.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 values        ContentValues 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.