Example of implementing the binder service at the c ++ layer and the binder example
View Example address: https://github.com/langxianwen/binder-demo
This article studies the implementation of the binder service and wants to write a binder example.
There are similar examples on the Internet and in books. After reading the examples, I found that they didn't want them, and they didn't quite match the source code style.
The binder service of the source code is simplified.
Problems:
1. frameworks/native/include/binder/IInterface. h: 50: error: undefined reference to 'android: RefBase ::~ RefBase ()'
Cause: No libbinder library is added, and no libutils library is added,
2. Where can I include the header file ITest. h TestService. h.
I put it in framework/av/include/media.
You only need to # include <media/ITest. h> for reference.
But can I store it in any directory defined by myself? For example:./test/include/test/ITest. h
# Include "ITest. h": the header file cannot be found during compilation. You also need to specify the header file path in Android. mk.
LOCAL_C_INCLUDES: = $ (LOCAL_PATH)/../include/test.
3. In my example, the log is printed using ALOGE. Some code libraries contain LOGE
Example writing experience: despite several lines of code, I had to spend two or three days. Yes, it will never be. It is the truth to do it first.
Code view Address: https://github.com/langxianwen/binder-demo
Git path: git clone https://github.com/langxianwen/binder-demo.git
How does android send data to activity in service?
One is to register a BroadcastReceiver in the Activity, as the landlord said. After the Service completes a task, it can send a broadcast. After receiving the broadcast, the receiver notifies the activity to perform corresponding operations.
In addition, bindserviceis used to associate serviceand application. all components in application .apk generally run in the same process. Therefore, IPC is not required. After bindService is successful, the Service Client can obtain an iBinder reference returned by the Service, for more information, see the Service documentation and the onBind example, so that Service references can be obtained through the returned iBinder object, as shown in
Public class LocalService extends Service {
// This is the object that calls es interactions from clients. See
// RemoteService for a more complete example.
Private final IBinder mBinder = new LocalBinder ();
Public class LocalBinder extends Binder {
LocalService getService (){
Return LocalService. this;
}
}
@ Override
Public IBinder onBind (Intent intent ){
Return mBinder;
}
}
After the Client obtains the Service object reference through this iBinder object, it can directly communicate with the Service, for example, reading the value in the Service or calling the Service method.
What are the famous computer viruses in history? How many examples are there?
BotNet