TAILIEUCHUNG - Lập trình Androi part 56

Lõi Android đội đã thường làm một công việc tốt trong việc giữ ổn định các API, và hỗ trợ một mô hình lời cầu xin khi họ thay đổi các API. Trong Android, bị phản đối không có nghĩa là nó đi xa, chỉ là tiếp tục sử dụng của nó là nản. Và, tất nhiên, các API mới được phát hành với tất cả các cập nhật Android mới. Thay đổi để các API cũng được phát hành tài liệu với nhau thông qua một báo cáo khác biệt API | CHAPTER 38 Handling Platform Changes Handling API Changes The core Android team has generally done a good job of keeping APIs stable and supporting a deprecation model when they change APIs. In Android being deprecated does not mean it is going away just that its continued use is discouraged. And of course new APIs are released with every new Android update. Changes to the APIs are well documented with each release via an API differences report. Unfortunately the Android Market the primary distribution channel for Android applications allows you to upload only one APK file for each application. Hence you need that one APK file to deal with as many Android versions as possible. Many times your code will just work and not require changing. Other times though you will need to make adjustments particularly if you want to support new APIs on new versions while not breaking old versions. Let s examine some techniques for handling these cases. Detecting the Version If you just want to take different branches in your code based on version the easiest thing to do is inspect . This public static integer value will reflect the same API level as you use when creating AVDs and specifying API levels in the manifest. So you can compare that value to say to see whether you are running on Android or newer. Wrapping the API So long as the APIs you try to use exist across all Android versions you are supporting just branching may be sufficient. Where things get troublesome is when the APIs change such as when there are new parameters to methods new methods or even new classes. You need code that will work regardless of Android version yet lets you take advantage of new APIs where available. There is a recommended trick for dealing with this reflection plus a wee bit of caching. For example back in Chapter 8 we used getTag and setTag to associate an arbitrary object with a View. Specifically we used this to associate a .

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.