USING AIDL TO SUPPORT INTER-PROCESS COMMUNICATION FOR SERVICESIn Chapt dịch - USING AIDL TO SUPPORT INTER-PROCESS COMMUNICATION FOR SERVICESIn Chapt Việt làm thế nào để nói

USING AIDL TO SUPPORT INTER-PROCESS

USING AIDL TO SUPPORT INTER-PROCESS COMMUNICATION FOR SERVICES
In Chapter 9, “Working in the Background,” you learned how to create Services for your applications. Here, you’ll learn how to use the Android Interface Definition Language (AIDL) to support rich inter-process communication (IPC) between Services and other application compo¬nents, including components running within different applications or within separate processes.
This gives your Services the capability to support multiple applications across process boundaries.
To pass objects between processes, you need to deconstruct them into OS-level primitives that the underlying OS can then marshal across application boundaries. This is done by implementing them as Parcelables.
AIDL is used to simplify the code that lets your processes exchange objects. It’s similar to interfaces like COM or Corba in that it lets you create public methods within your Services that can accept and return object parameters and return values between processes.
Implementing an AIDL Interface
AIDL supports the following data types:
► Java language primitives (int, boolean, float, char, etc.).
► String and CharSequence values.
► List objects (including generics), where each element is a supported type. The receiving class will always receive the List object instantiated as an ArrayList.
► Map objects (not including generics), where every key and element is of a supported type. The receiving class will always receive the Map object instantiated as a HashMap.
► AIDL-generated interfaces (covered later). An import statement is always needed for these.
► Classes that implement the Parcelable interface (covered next). An import statement is always needed for these.
The following sections demonstrate how to make your classes Parcelable, create an AIDL Service definition, and implement and expose that Service definition for use by other application components.
Making Classes Parcelable
In order for non-native classes to be passed between processes, they must implement the Parcelable interface. This lets you decompose the properties within your classes into primitive types stored within a Parcel that can be marshaled across process boundaries.
Implement the writeToParcel method to decompose your class object, using the write* methods to save object properties into the outgoing Parcel object:
public void writeToParcel(Parcel out, int flags) { out.writeLong(myLong); out.writeString(myString); out.writeDouble(myDouble);
To re-create an object that’s been saved as a parcel, implement the public static Creator field (which implements a new Parcelable.Creator class) to create a new object based on an incoming Parcel by reading the incoming parcel using its read* methods:
private MyClass(Parcel in) { myLong = in.readLong(); myString = in.readString(); myDouble = in.readDouble();
}
Listing 18-13 shows a basic example of using the Parcelable interface for the Quake class you’ve been using in the ongoing Earthquake example.


0/5000
Từ: -
Sang: -
Kết quả (Việt) 1: [Sao chép]
Sao chép!
USING AIDL TO SUPPORT INTER-PROCESS COMMUNICATION FOR SERVICESIn Chapter 9, “Working in the Background,” you learned how to create Services for your applications. Here, you’ll learn how to use the Android Interface Definition Language (AIDL) to support rich inter-process communication (IPC) between Services and other application compo¬nents, including components running within different applications or within separate processes.This gives your Services the capability to support multiple applications across process boundaries.To pass objects between processes, you need to deconstruct them into OS-level primitives that the underlying OS can then marshal across application boundaries. This is done by implementing them as Parcelables.AIDL is used to simplify the code that lets your processes exchange objects. It’s similar to interfaces like COM or Corba in that it lets you create public methods within your Services that can accept and return object parameters and return values between processes.Implementing an AIDL InterfaceAIDL supports the following data types:► Java language primitives (int, boolean, float, char, etc.).► String and CharSequence values.► List objects (including generics), where each element is a supported type. The receiving class will always receive the List object instantiated as an ArrayList.► Map objects (not including generics), where every key and element is of a supported type. The receiving class will always receive the Map object instantiated as a HashMap.► AIDL-generated interfaces (covered later). An import statement is always needed for these.► Classes that implement the Parcelable interface (covered next). An import statement is always needed for these.The following sections demonstrate how to make your classes Parcelable, create an AIDL Service definition, and implement and expose that Service definition for use by other application components.Making Classes ParcelableIn order for non-native classes to be passed between processes, they must implement the Parcelable interface. This lets you decompose the properties within your classes into primitive types stored within a Parcel that can be marshaled across process boundaries.Implement the writeToParcel method to decompose your class object, using the write* methods to save object properties into the outgoing Parcel object:public void writeToParcel(Parcel out, int flags) { out.writeLong(myLong); out.writeString(myString); out.writeDouble(myDouble); To re-create an object that’s been saved as a parcel, implement the public static Creator field (which implements a new Parcelable.Creator class) to create a new object based on an incoming Parcel by reading the incoming parcel using its read* methods:private MyClass(Parcel in) { myLong = in.readLong(); myString = in.readString(); myDouble = in.readDouble();}Listing 18-13 shows a basic example of using the Parcelable interface for the Quake class you’ve been using in the ongoing Earthquake example.
đang được dịch, vui lòng đợi..
Kết quả (Việt) 2:[Sao chép]
Sao chép!
SỬ DỤNG AIDL HỖ TRỢ THÔNG TIN LIÊN TỤC CHO DỊCH VỤ
Trong chương 9, "Làm việc trong nền", bạn đã học cách để tạo ra dịch vụ cho các ứng dụng của bạn. Ở đây, bạn sẽ tìm hiểu làm thế nào để sử dụng các ngôn ngữ định nghĩa giao diện Android (AIDL) để hỗ trợ phong phú truyền thông liên tiến trình (IPC) giữa dịch vụ và compo¬nents ứng dụng khác, bao gồm các thành phần hoạt động trong các ứng dụng khác nhau hoặc trong quy trình riêng biệt.
Điều này cho phép bạn Dịch vụ khả năng hỗ trợ nhiều ứng dụng trên ranh giới quy trình.
để vượt qua các đối tượng giữa các quá trình, bạn cần phải tháo gỡ chúng thành nguyên thủy mức hệ điều hành hệ điều hành cơ bản sau đó có thể sắp xếp qua ranh giới ứng dụng. Điều này được thực hiện bằng cách thực hiện chúng như Parcelables.
AIDL được sử dụng để đơn giản hóa mã cho phép đối tượng trao đổi các quá trình của bạn. Nó tương tự như giao diện như COM hay CORBA ở chỗ nó cho phép bạn tạo ra các phương pháp công trong dịch vụ của bạn có thể chấp nhận và thông số trở về đối tượng và trả về giá trị giữa các quá trình.
Thực hiện một giao diện AIDL
AIDL hỗ trợ các kiểu dữ liệu sau đây:
nguyên thủy ngôn ngữ ► Java (int, boolean, float, char, vv.)
giá trị CharSequence. ► string và
đối tượng ► Danh sách (bao gồm cả thuốc generic), trong đó mỗi phần tử là một loại hỗ trợ. Lớp nhận sẽ luôn nhận được danh sách đối tượng cụ thể như một ArrayList.
Đối tượng ► Bản đồ (không bao gồm thuốc generic), nơi mà mỗi phím và phần tử là một loại hỗ trợ. Lớp tiếp nhận sẽ luôn nhận được những đối tượng đồ instantiated như một HashMap.
Giao diện ► AIDL tạo (bảo hiểm sau này). Một tuyên bố nhập khẩu là luôn luôn cần thiết cho các.
► Các lớp mà thực hiện các giao diện Parcelable (trong phần tiếp theo). Một tuyên bố nhập khẩu là luôn luôn cần thiết cho các.
Các phần sau đây chứng minh làm thế nào để làm cho lớp học của bạn Parcelable, tạo ra một định nghĩa AIDL Dịch vụ, thực hiện và phơi bày rằng định nghĩa dịch vụ để sử dụng bởi các thành phần ứng dụng khác.
Làm Lớp Parcelable
Để cho lớp học không có nguồn gốc để được thông qua giữa các quá trình, họ phải thực hiện giao diện Parcelable. Điều này cho phép bạn phân hủy các thuộc tính trong lớp học của bạn thành các loại nguyên thủy được lưu trữ trong một bưu kiện có thể được marshaled qua ranh giới quy trình.
Thực hiện các phương pháp writeToParcel để phân hủy đối tượng lớp học của bạn, bằng cách sử dụng phương pháp ghi * để tiết kiệm tài sản đối tượng vào các đối tượng Parcel đi:
công cộng làm mất hiệu lực writeToParcel (Parcel ra, int cờ) {out.writeLong (MyLong); out.writeString (myString); out.writeDouble (myDouble);
Để tái tạo một đối tượng mà đã được lưu như một bưu kiện, thực hiện các công trường tạo tĩnh (mà thực hiện một lớp Parcelable.Creator mới) để tạo ra một đối tượng mới dựa trên một bưu kiện đến bằng cách đọc đến bưu kiện sử dụng của nó đọc * phương pháp:
MyClass tin (Parcel in) {MyLong = in.readLong (); myString = in.readString (); myDouble = in.readDouble ();
}
Liệt 18-13 cho thấy một ví dụ cơ bản của việc sử dụng các giao diện Parcelable cho lớp Quake bạn đã sử dụng trong ví dụ động đất liên tục.


đang được dịch, vui lòng đợi..
 
Các ngôn ngữ khác
Hỗ trợ công cụ dịch thuật: Albania, Amharic, Anh, Armenia, Azerbaijan, Ba Lan, Ba Tư, Bantu, Basque, Belarus, Bengal, Bosnia, Bulgaria, Bồ Đào Nha, Catalan, Cebuano, Chichewa, Corsi, Creole (Haiti), Croatia, Do Thái, Estonia, Filipino, Frisia, Gael Scotland, Galicia, George, Gujarat, Hausa, Hawaii, Hindi, Hmong, Hungary, Hy Lạp, Hà Lan, Hà Lan (Nam Phi), Hàn, Iceland, Igbo, Ireland, Java, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, Kurd, Kyrgyz, Latinh, Latvia, Litva, Luxembourg, Lào, Macedonia, Malagasy, Malayalam, Malta, Maori, Marathi, Myanmar, Mã Lai, Mông Cổ, Na Uy, Nepal, Nga, Nhật, Odia (Oriya), Pashto, Pháp, Phát hiện ngôn ngữ, Phần Lan, Punjab, Quốc tế ngữ, Rumani, Samoa, Serbia, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenia, Somali, Sunda, Swahili, Séc, Tajik, Tamil, Tatar, Telugu, Thái, Thổ Nhĩ Kỳ, Thụy Điển, Tiếng Indonesia, Tiếng Ý, Trung, Trung (Phồn thể), Turkmen, Tây Ban Nha, Ukraina, Urdu, Uyghur, Uzbek, Việt, Xứ Wales, Yiddish, Yoruba, Zulu, Đan Mạch, Đức, Ả Rập, dịch ngôn ngữ.

Copyright ©2024 I Love Translation. All reserved.

E-mail: