In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to parse Android ApiDemo idiomatic code, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
1. About Dialog
|-com.example.android.apis.app/AlertDialogSamples.java
It contains a variety of uses of Dialog, with 10 different Dialog instances.
|-com.example.android.apis.app/FragmentDialog.java
To implement Dialog using DialogFragment, you can use onCreateView () to create a Dialog layout, or you can use the getDialog () method of the DialogFragment class, where you can use the method you created earlier to return a Dialog.
Android officially recommends the use of DialogFragment.
II. About Pregerence
|-com.example.android.apis.preference
This package introduces the use of Preference, including the use of Code and XML (addPreferencesFromResource) to achieve preference layout, using setListFooter can add a layout at the bottom (the code is to add a Button at the bottom)
III. About Service
There are two ways to create Servcie: startService () and bindServcie (): the purpose of the service created by startService () is only to start and terminate the service, while the service created by bindServcie () is for the remote control of the service (usually a service object instance is obtained).
|-com.example.android.apis.app/LocalServcie.java
After the service created by startService () has called the onCreate () method, it will continue to call the onStartCommand () method, which has a return value that can be used to set whether to restart after the Servcie is forcibly shut down
By adding Log to the code, the execution flow of bindServcie () is obtained: 1. The client requests the connection service bindServcie ()-> 2. After the bound service is generated, Android invokes the service's onBind () callback method to handle the service binding, and the onBind () method returns an IBinder object to communicate with the service-> 3. The onServiceConnected (cn,IBinder) method of the ServcieConnection object on the client side uses the IBinder object passed in step 2 to call the getService () on the server side to get the service instance.
|-com.example.android.apis.app/RemoteServcie.java
AIDL is an interface definition language, which is used to restrict the communication rules between two processes and for the compiler to generate code to realize the communication between two processes on Android devices.
Taking the ISecondary.aidl file as an example, Android automatically generates the code needed to bind the remote service according to the interface defined in the AIDL file. The execution process of the whole bindServcie () is as follows:
1. Process A calls bindServcie () to request a connection to RemoteService
two。 Process B calls back the onBind () method after the service is generated, generates an IBinder object for processing Binder IPC, and returns
3. Process A calls the callback method onServiceConnected () method, takes the IBinder returned by onBind (), passes it to the IScondary.Stub.asInterface () function, and uses it to generate a service proxy object bound to the RemoteService service, ISeondary.Stub.Proxy,***, to save it in the mSecondaryService member variable. At this point, the binding of RemoteService's ISecondary interface is complete.
4. Process An invokes the getPid () proxy method of the RemoteService service using the service proxy object ISeondary.Stub.Proxy
5.Binder IPC: the service proxy object ISeondary.Stub.Proxy passes Binder IPC data to the service Binder object ISeondary.Stub
6. Process B calls the getPid () Stub method of the RemoteService service. After the ISeondary.Stub service Binder object acquires the Binder IPC data, it calls the getPid () Stub method implemented in the RemoteService service to return the service process ID to process A.
After reading the above, do you have any further understanding of how to parse Android ApiDemo idiomatic code? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.