unable to start service from AsyncTask

2019-03-04 07:10发布

问题:

I am trying to start service from AsyncTask but cant see that its starts. I also added Service on manefast file.

here the code:

protected Integer  doInBackground(Void... values) throws InterruptedException {
    //starts service number activite
    Intent serviceIntent = new Intent();
    serviceIntent.setAction("services.conServise");
    context.startService(serviceIntent);

and the manifest file:

   <service android:name="services.conServise"></service>

  </application>

thanks for help.

回答1:

services.conServise should be in a <action> tag within the <intent-filter> tag for that declaration of service, please replace servicesclassname with the appropriate package name for example, org.mypkg.foo.bar.

<service android:name="<servicesclassname>">
    <intent-filter>
        <action android:name="services.conServise"/>
    </intent-filter>
</service>


回答2:

Try it via onPostExecute() method in AsyncTask class. Thanks