First of all, I have a lib library, which defines a Service:
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
<service
android:name=".SharedService"
android:process="com.lib.aidl.SharedService"
android:enabled="true"
android:exported="true">
</service>
</application>
Now, add two apps that have introduced this library, and then called them in their respective codes:
startService(new Intent(context, SharedService.class))
What I am thinking now is that there should be only one instance of SharedService
in the system, in the process com.lib.aidl.SharedService
.
But the actual situation is that there are two instances of SharedService
, they are both in the process named com.lib.aidl.SharedService
, but the process ids are different . why is that?
Now I want only one instance of SharedService
to appear in the system. When startService
is called for the second time, the onStartCommand
method will be called back. Can this be done? ?
将
替换成
试试
注意,加了个 ':'