When communicating between processes, it is often designed to open a remote service. There are two ways to open a remote service, one is to open it explicitly, and the other is to open it implicitly. Let's look at them separately:
1. Implicitly open
Server : The configuration in AndroidManifest.xml where the Service is located is as follows, note that exported = "true", only if it is true can it be accessed by other apps, otherwise it is limited to the application.
<service android:name=".BookManagerService" android:exported="true"> <intent-filter> <action android:name="com.sl.aidl"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </service>
Client : need to enable remote service
Intent service = new Intent(); service.setAction("com.sl.aidl"); //service 的 action 值 service.setPackage( "com.sl.binderservice" ); //The name of the package where the remote service is located
// Binding service bindService(service, mConnection, Context.BIND_AUTO_CREATE);
// Start the service
startService(service);
Second, the display is turned on
Server : AndroidManifest.xml
<service android:name=".BookManagerService" android:exported="true"/>
Client :
public static final String NAME_REMOTE_SERVICE = "com.sl.aidl" ; public static final String PACKAGE_REMOTE_SERVICE = "com.sl.binderservice" ; //启动服务 Intent startIntent = new Intent (); ComponentName componentName = new ComponentName(PACKAGE_REMOTE_SERVICE ,NAME_REMOTE_SERVICE); startIntent .setComponent (componentName ); startService( startIntent) ; // Binding service Intent startIntent = new Intent (); ComponentName componentName = new ComponentName(PACKAGE_REMOTE_SERVICE ,NAME_REMOTE_SERVICE); startIntent .setComponent (componentName ); bindService( startIntent, mConnection, Context.BIND_AUTO_CREATE) ;
These are the two opening methods.