TAILIEUCHUNG - Lập trình Androi part 40

Xây dựng một nhà cung cấp nội dung có lẽ là phức tạp và tẻ nhạt nhất trong tất cả các nhiệm vụ của Android phát triển. Có rất nhiều yêu cầu của một nhà cung cấp nội dung, về phương pháp thực hiện và dữ liệu công cộng thành viên cung cấp. Và, cho đến khi bạn hãy thử sử dụng nhà cung cấp nội dung của bạn, bạn không có cách tuyệt vời kể nếu bạn đã làm nó một cách chính xác (so với, nói, xây dựng một hoạt động và nhận được xác nhận lỗi từ. | Chapter Building a Content Provider Building a content provider is probably the most complicated and tedious task in all of Android development. There are many requirements of a content provider in terms of methods to implement and public data members to supply. And until you try using your content provider you have no great way of telling if you did it correctly versus say building an activity and getting validation errors from the resource compiler . That being said building a content provider is of huge importance if your application wishes to make data available to other applications. If your application is keeping its data solely to itself you may be able to avoid creating a content provider and just access the data directly from your activities. But if you want your data to possibly be used by others for example you are building a feed reader and you want other programs to be able to access the feeds you are downloading and caching then a content provider is right for you. This chapter shows some sample bits of code from the ContentProvider ConstantsPlus application. This is the same basic application as was first shown back in Chapter 22 but rewritten to pull the database logic into a content provider which is then used by the activity. First Some Dissection As discussed in the previous chapter the content Uri is the linchpin behind accessing data inside a content provider. When using a content provider all you really need to know is the provider s base Uri. From there you can run queries as needed or construct a Uri to a specific instance if you know the instance identifier. However when building a content provider you need to know a bit more about the innards of the content Uri. 265 A content Uri has two to four pieces depending on the situation It always has a scheme content indicating it is a content Uri instead of a Uri to a web resource http . It always has an authority which is the first path segment after the scheme. The authority is a unique string

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.