Udacity Android Practice Note: Lesson 4 Part A

Source: Internet
Author: User

Udacity Android Practice Note: Lesson 4 Part A

/titer1/archimedes of dry Goods shop chores
Source: Https://code.csdn.net/titer1
Contact: 13,073,161,968 (SMS Best)
Disclaimer: This document is licensed under the following protocols: Free reprint-Non-commercial-non-derivative-retention Attribution | Creative Commons by-nc-nd 3.0, reproduced please specify the author and source.
Tips:https://code.csdn.net/titer1/pat_aha/blob/master/markdown/android/

Preface

This isWeekend Time Last  Time, we have learn form theVideo andNow, we areRun  theCode directly.let US go.thanks Jackson version change rs232 uart txd rxd CLK115200 TenKusb atLeast5, Transport type1.0Fullspeded <TenM2.0Highspeedd, -M?720P -FPS printer more high than UVC USB mass storage. Dirver-inside3.0> -Mi2c2Line. CLK Data -K bps, command
data,看看 数据里面 有没有 traped in weather station,就知道当前情况了

Other four components

Service
Broad
Content provider
Activity

4.01 Life cycle



以上介绍了 声明周期
!! Hands-on notes life cycle

To see the life cycle of activity is
Look at Mainactivity's logcat, very clear.

Operation Cloth

Enter mainactivity–> detail activity–> back to Mainactivity

And the Main activity–> seting–> back.

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


-Contract
-DB Builder
-Content provider One of the four components

4.02 fourth most basic code framework


-Complete Test framework
-Added location Weather's contract
-Added location weather related SQL Builder

4.03 defining database table entries for Locationcontract interpretation
/** * Defines table and column names for the weather database. */

is to define the table contents

The update here is to add a
Column content definition for location table

4.04 Perfect location database-target test weather database creation/insertion

At the database initialization code,
The location of Weatherdbhelper,
Modeled after the creation of the weather database,
Add the following code

 Public  class weatherdbhelper extends sqliteopenhelper {    Static FinalString database_name ="Weather.db";@Override     Public void onCreate(Sqlitedatabase sqlitedatabase) {FinalString sql_create_location_table ="CREATE TABLE"+ Locationentry.table_name +" ("+ locationentry._id +"INTEGER PRIMARY KEY,"+ locationentry.column_location_setting +"TEXT UNIQUE is 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);//Newly addedSqlitedatabase.execsql (sql_create_weather_table);
Enable database to create test program Testcreatedb

Program Introduction

Students:uncomment This test once you ' ve written theCode toCreate theLocation table. Note thatYou'll have toHave chosen theSame column names thatI didinch mySolution forThis test toCompile, soifYou haven ' t yet done that, this isA good Time  toChange your column names toMatch mine. Note thatThis is only tests that  theLocation table have theCorrect columns,sinceWe give you theCode for  theWeather table. This testdoes  notLook at  the
Enable Test utilites
    / * Students:you can uncomment this helper function once you have finished creating the Locationentry PA     RT of the Weathercontract. */    StaticContentvalues Createnorthpolelocationvalues () {//Create a new map of values, where column names is the keysContentvalues testvalues =NewContentvalues ();        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);returnTestvalues; }/ * Students:you can uncomment this function once you have finished creating the locationentry part of T     He weathercontract as well as the weatherdbhelper. */    Static LongInsertnorthpolelocationvalues (Context context) {//Insert our test records into the databaseWeatherdbhelper DBHelper =NewWeatherdbhelper (context);//I know that here will create a table sqlitedatabase db = Dbhelper.getwritabledatabase (); Contentvalues testvalues = Testutilities.createnorthpolelocationvalues ();LongLocationrowid; Locationrowid = Db.insert (WeatherContract.LocationEntry.TABLE_NAME,NULL, testvalues);//Insert the test table here        //Verify We got a row back.Asserttrue ("error:failure to insert North Pole location Values", Locationrowid! =-1);returnLocationrowid; }

The above three files are updated

4.05 Test Location Table

Here's a recent update

This section can be further refined from the comments

The following section will be enriched with code

  / * Students:here is where you'll build code to test so 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 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 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}```###6Step Test table (Insert/quiery ...) All the updated code in this "' Java Public void testlocationtable() {//First Step:get reference to writable database        //If there ' s an error in those massive SQL table creation Strings,        //Errors'll is thrown here and you try to get a writable database.Weatherdbhelper DBHelper =NewWeatherdbhelper (Mcontext); Sqlitedatabase db = Dbhelper.getwritabledatabase ();//Second step:create contentvalues of what's 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        LongLocationrowid; Locationrowid = Db.insert (WeatherContract.LocationEntry.TABLE_NAME,NULL, testvalues);//Verify We got a row back.Asserttrue (Locationrowid! =-1);//Data ' s inserted.  In theory. Now pulling 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 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 this there is a 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 effect

This is waiting for the internet, there should be a specific display,
Initially see there are several assert

Operating method: Lesson 4a 28-sqliteopenhelper and Sunshine Database.mp4

I put the problem of the environment to run the method has been sorted, to be updated later

4.06 Test Weather Table

As with the above, only Testdb.java is modified.

编辑器里面 有 主题切换,可以后界面颜色 ,字体,保护眼睛,你懂的<divclass="se-preview-section-delimiter"></div>
    • It's not just like a test*****talbe function that's been re-written.
    • In the Testweathertalbe program, the code for the Testloactiontalbe is called First,
      The code is encapsulated as insertlocation, but the content is testlocationtable.

    • The return value of the function is the ROWID after the corresponding item query.

The code for both joins is as follows,

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

At this point, the logic is correct, two data tables are tested
The goal for the future is 4.24. There's a lot more.

-Give a preliminary table frame to create the weather table
-Create a location table
-Fill Test location
-Fill test Weather location (insert query ..., call the result of Testlocation)

In a word, midterm 4.06 is a small milestone.

Udacity Android Practice Note: Lesson 4 Part A

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.