Android – how do I start services defined in different packages?

I have two applications, one running in the namespace com.gtosoft.voyager and the other com.gtosoft.dash. From com.gtosoft.dash, I want to start the services defined in com.gtosoft.voyager

I think I need an intention, but will I pass Arg (s) to the intention before starting with startservice()?

If they're in the same package I can use

Intent svc=new Intent (SettingsActivity.this,VoyagerService.class);
startService(svc);

The fragment in listing defines the service

<application android:icon="@drawable/voyagercarlogo" android:label="@string/app_name" android:debuggable="false">

    <provider android:name="com.gtosoft.voyager.VoyagerCProvider" 
        android:authorities="com.gtosoft.voyager"/>

    <service android:name=".VoyagerService"/>

    <activity android:name=".SettingsActivity" 
            android:label="Voyager"
            android:configChanges="keyboardHidden|orientation">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

resolvent:

I will set up an < intent Filter > on the service, use a custom action, and then use it in your intent to start or bind to the service. You can see an example in this pair of client and service sample projects

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>