Với mảnh vỡ tại có sẵn như là một phần của thư viện hỗ trợ Android, họ cung cấp một thay thế encapsu¬lated hơn với các thành phần song song.
Thay vì là nhân đôi hoạt động, sử dụng mảnh vỡ - kết hợp với hệ thống phân cấp tài nguyên - để tạo ra một giao diện người dùng phù hợp tối ưu hóa cho phiên bản nền tảng khác nhau và cấu hình phần cứng.
Hầu hết các logic UI cho hoạt động của bạn phải được chứa trong Fragments cá nhân chứ không phải là các Hoạt động chính nó. Kết quả là, bạn chỉ cần tạo ra mảnh vỡ khác để phơi bày và sử dụng các chức năng khác nhau và thổi phồng
các phiên bản khác nhau của cùng một bố trí được lưu trữ trong res của mình / layout-v [cấp API] thư mục.
Tương tác giữa và trong các mảnh vỡ thường được duy trì trong mỗi Fragment , do đó, chỉ liên quan đến tiến API mất tích sẽ cần phải được thay đổi trong hoạt động. Nếu mỗi biến thể của một Fragment thực hiện các định nghĩa giao diện tương tự và ID, bạn không cần phải tạo ra nhiều hoạt động hỗ trợ nhiều layout và định nghĩa Fragment.
Tối ưu hóa giao diện người dùng THI VỚI PHƯƠNG THỨC nghiêm ngặt
Bản chất nguồn lực hạn chế của các thiết bị di động khuếch đại hiệu quả của việc thực hiện thời gian consum¬ing hoạt động trên thread ứng dụng chính. Truy cập vào tài nguyên mạng, đọc hoặc viết các tập tin, hoặc truy cập vào cơ sở dữ liệu trong khi chặn thread UI có thể có một tác động đáng kể trên experi¬ence người dùng, làm ứng dụng của bạn để trở thành kém mịn, lag hơn, và, trong trường hợp cực đoan nhất, không phản hồi.
bạn đã học được làm thế nào để chuyển hoạt động tốn nhiều thời gian như vậy vào đề nền trong Chương 9. Chế độ nghiêm ngặt (giới thiệu trong Android 2.3 (API cấp 9) là một công cụ giúp bạn xác định trường hợp, bạn có thể bỏ qua.
Sử dụng các API chế độ nghiêm ngặt, bạn có thể gán một bộ chính sách mà theo dõi hành động trong appli¬cation của bạn và xác định cách bạn nên báo trước. bạn có thể xác định các chính sách liên quan đến một trong hai chủ đề ứng dụng hiện tại hoặc để máy ảo (VM) quá trình ứng dụng của bạn. Điều thứ nhất là hoàn hảo cho việc phát hiện chậm các hoạt động được thực hiện trên thread UI, trong khi sau này sẽ giúp bạn phát hiện rò rỉ bộ nhớ và bối cảnh.
để sử dụng chế độ nghiêm ngặt, tạo ra một lớp ThreadPolicy mới và một lớp VmPolicy mới, sử dụng các lớp học xây dựng tĩnh của họ với các phát hiện phương pháp * để xác định các hành động giám sát. Các hình phạt tương ứng * phương pháp kiểm soát cách hệ thống nên phản ứng để phát hiện những hành động.
Các chính sách chủ đề có thể được sử dụng để phát hiện đĩa đọc / ghi và truy cập mạng, trong khi chính sách Vm có thể giám sát ứng dụng của bạn để hoạt động, SQLite, và rò rỉ đối tượng closeable.
các hình phạt dành cho cả hai chính sách bao gồm khai thác gỗ hoặc tử vong ứng dụng, trong khi các chính sách đề cũng hỗ trợ hiển thị một hộp thoại trên màn hình hoặc nhấp nháy màn hình biên giới.
cả hai lớp người xây dựng cũng bao gồm một phương pháp detectAll bao gồm tất cả các tùy chọn theo dõi có thể được hỗ trợ bởi nền tảng máy chủ. Bạn cũng có thể sử dụng phương pháp strictMode.enableDefaults áp dụng giám sát mặc định và lựa chọn hình phạt.
Để kích hoạt chế độ nghiêm ngặt trên toàn bộ ứng dụng của bạn, bạn nên mở rộng các lớp ứng dụng, như trong Liệt kê 18-19.
đang được dịch, vui lòng đợi..