Udacity android Study Notes: lesson 4 part B, udacityandroid

Source: Internet
Author: User

Udacity android Study Notes: lesson 4 part B, udacityandroid
Udacity android Study Notes: lesson 4 part B

Prepared by: Taobao stores/titer1/Archimedes
Source: https://code.csdn.net/titer1
Contact: September 1307316
Statement: This article uses the following agreement for authorization: Free Reprint-non commercial-Non derivative-keep the signature | Creative Commons BY-NC-ND 3.0, reprint please indicate the author and the source.
Tips: https://code.csdn.net/titer1/pat_aha/blob/master/Markdown/android/

Lesson 4b. Later versions will be split into 4 sections. We strongly recommend that you keep your renamed subtitles and re-press 29 units are waitted. The last chapter has created the db and content, this chapter will talk about content provider and look forward to the great unity (Summary) of all content)
Why contents providers matter


How to understand the relationship between multiple apps and one content provider

Create a content provider

More todo

In-depth analysis of contentProvider,
See extends uctor notes below
In the api sdk

1.1 what is URI

Data is assiated with views in the terms of universal resource identifiers or URIs.

In a word, universal resource identifiers
See also observer mode the code register an android construct called a content observer
1.2 how to build a content provider


-Determine URIs
-Update contract
-Fill out URI matcher
-Implement fuctions

1.2.1 define a URI


-Weather/location for insert/update/delete
-Weather_with_location: multiple days
-Weather_with_location_and_date: daily Condition

Review contractit is an agreement etween the data models, storrage, and views. Next, we will talk about how to update contract.
1.2.2 update URI

4b-3 lesson todo? Why is it necessary to bind a string of numbers? A URI corresponds to a constant? The best thing is to add debugging records (dynamic) here)

This section describes the changes to the weatherContract class.
-Add content_URI
-Add content_type

Careful people will find that the part is to prepare for URI Initialization


This is the location where subsequent code tracking is required. The query is constructed here.

Build uri

Below is the checklist

See. Note the difference between the current graph and the above two graphs.
-Buildweatheruri is not implemented before.

1.2.3 fill out URImatcher

Urimatcher:
Uses a simple expression ayntax to help us match URI's for a content provider

Intuition, Regular Expression


-# Indicates number
-* Indicates a string.

Practice time

Let's see what to do next.


The code is like this.

Previously, it was fake data, and now it is a database-based data uri.
1.2.4 content provider1 2 4 1 register the content provider
Review, what is contact? Conventions? Go to the test provider stage,

Lesson 4b_9 now

1 2 4 2 content provider replace the SQL?

Register now, tell all (include pakage manager) by xml format

Here, the content resolver can resolve it!

Next to do:

Now, code time

1 2 4 3 code the content rovider oncreate

Always think that this is the last step, contenprovider... here is the onCreate

Gettype is a function of content provider.

The function is used to test the use of uribuilder.
In addition, our task is to add weather_with_location_and_date and other responses.

Reading comments is here

The original testGetYpe is introduced here, but it will not be used in the end! Note
See todo list again

However, the answer will soon be available,
Compared with the previous graph, we have added two uri types.

1 2 4 4 difficult to code the content rovider query
I just marked the sub-title, oh, yeah! I quietly watched the video options of prtplayer and wondered how to modify the integrated image quality of the multimedia player! Yeah! Carefully click on historical version records to learn about the development process of potplayer!


This is query, a complicated function in the legend.

Below is the bottom of the query function.

  • Tell the observer they listen to the changes that happen to that URI and any of its descendants
In the observer mode, the underlying layer of the interface is added, subtracted, or changed. It is said that there are more than one setNotificationUri to be confirmed.

When all the query code is added, we can open the following comments to test our provider

Come on, it's another task.

This is the time to complete all the queries, aha!

First weahther query code:

Then, location query code:

In the preliminary comparison, the table name is the first parameter intuitively.

If two tables are created, the two tables are independent, but the inner needs to join them.
So

Meaning:
Tbl inner join tbl2 on tbl. loc_key = tbl2.id

The following is selection, which I think helps the memory

The following describes how to call sqlbuilder query functions,
-Sqlbuiler is called)
-Used the encapsulated selection character Function
-The parameter (location/startDate) is from uri


The preceding statement only contains location. The following statement contains both location and date for query.

The preceding two functions are called. the query of the content provider

You can draw a call to digoal for the above three function diagrams. Others: Is there any online SQL database syntax exercise online SQL?
Nap
  • If you query a single table (only weather or Location is used), you can directly call the query function of content provider.
    SQL-related qurey Functions
  • If the query involves two tables, it must be processed separately. sqliteQueryBuilder is used here.

The query operation is complete, but there are other operations in Step 4. Continue

Task insert


The previous article has two minutes, and the code is the above one, but the details
-Exception Handling
-Insert uri-related trick (go deep into todo when researching insert)


See the task card again. The goal is to improve the insert
"'
We strongly recommend that you keep your renamed subtitles and repress them.
"'

Get id for insert? Now:

Tell oberserver now:

Test-driven development:

Task update + delete

Lesson 4b_22 the routines here are the same as those of Inset. To get row courserr, tell obersver... have a test, you need to make a picture or complete the code. Then, add it. OK.
Todo
  • Update get couser

  • Update fun tell observer

  • Delete function get courser

  • Delete functionj tell obersver

  • Call the test unit to ganrantee the work

Efficient update & insert
Batch insertion is faster than one insert and encapsulates the intuition of the first round of transaction, which is not efficient. Is this to facilitate transaction rollback? How fast is todo thinking? 10 times?

Summary of content provider redux

In theory, I should give the classic image back to the station. In fact, we should extract subtitles and analyze them gradually. Todo's last sentence, "but we still use it in our code", will be used in the actual project in the future
Todocreat fetch weahter task
Rebuild a feather bot.

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.