Why is this simple service not starting?

前端 未结 5 1247
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 02:13

I have a service with a handler that has to write \"Hello\" in the logcat every 5 seconds. But it doesn\'t write nothing on the logcat... It\'s like the service is not execu

相关标签:
5条回答
  • 2020-12-15 02:46

    If using Xamarin Droid the easiest way to do this is to mark the class as a service like this:

    [Service]
    public class LongRunningTaskService : Service
    {
        ...
    }
    

    Then there's no need to put it in the AndroidManifest.xml.

    0 讨论(0)
  • 2020-12-15 02:51

    Did you declare the service in AndroidManifest.xml?

    0 讨论(0)
  • 2020-12-15 02:52

    Hi the code you write is working fine. May be you forgot to add the following code in the manifest file before closing application tag.

    <application>
        ....
        <service android:name=".MyServiceNotifications"/>
    </application>
    
    0 讨论(0)
  • 2020-12-15 02:52

    There are also circumstances where you need to put the "enabled" attribute to "true" when defining it in the manifest, like so:

    <service android:enabled="true" android:name=".MyServiceNotifications" />
    

    See this link for more info: http://developer.android.com/guide/topics/manifest/service-element.html

    0 讨论(0)
  • 2020-12-15 03:00

    Very important: write the name space correctly, for example:

    <service android:name="com.example.data.synchronization.SynchronizationService"/>
    

    in my AndroidManifest.xml previously it was (wrong):

    <service android:name="com.example.data.SynchronizationService"/>
    

    No service started and no error message!

    0 讨论(0)
提交回复
热议问题