TAILIEUCHUNG - Lập trình Androi part 36

Trong khi Android cung cấp cấu trúc lưu trữ, thông qua các ưu đãi và cơ sở dữ liệu, đôi khi một tập tin đơn giản sẽ đủ. Android cung cấp hai mô hình để truy cập các tập tin: một cho các tập tin được đóng gói sẵn với các ứng dụng của bạn và một cho các tập tin được tạo ra trên thiết bị của đơn của bạn. Cả hai của các mô hình này được bao gồm trong chương này. | Chapter Accessing Files While Android offers structured storage via preferences and databases sometimes a simple file will suffice. Android offers two models for accessing files one for files prepackaged with your application and one for files created on-device by your application. Both of these models are covered in this chapter. You and the Horse You Rode in On Let s suppose you have some static data you want to ship with the application such as a list of words for a spell checker. The easiest way to deploy that is to place the file in the res raw directory so it will be put in the Android application APK file as part of the packaging process as a raw resource. To access this file you need to get yourself a Resources object. From an activity that is as simple as calling getResources . A Resources object offers openRawResource to get an InputStream on the file you specify. Rather than a path openRawResource expects an integer identifier for the file as packaged. This works just like accessing widgets via findViewById . For example if you put a file named in res raw the identifier is accessible in Java as . Since you can get only an InputStream you have no means of modifying this file. Hence it is really useful just for static reference data. Moreover since it is unchanging until the user installs an updated version of your application package either the reference data must be valid for the foreseeable future or you will need to provide some means of updating the data. The simplest way to handle that is to use the reference data to bootstrap some other modifiable form of storage . a database but you end up with two copies of the data in storage. An alternative is to keep the reference data as is but keep modifications in a file or database and merge them together when you need a complete picture of the information. For example if your application ships a file of URLs you could have a second file that tracks URLs added by the user or .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.