Why doesn't my Service work in Android? (I just want to log something ever 5 seconds)

后端 未结 5 702
攒了一身酷
攒了一身酷 2020-12-14 18:44

I created a new class called HelloService. I added this to the Android manifest.xml.

public class HelloService extends Service {
    private Timer timer = ne         


        
相关标签:
5条回答
  • 2020-12-14 19:07

    Maybe you're not declaring the service in your manifiest. Anyway you're using the wrong class. You have to use AlarmManager for programing events. See that link, it was very useful to me.

    Use alarmManager and service to perform schedule notification only during specific time period

    0 讨论(0)
  • 2020-12-14 19:07

    A service has a life cycle as any other android application. For this reason it can occur that your service gets killed by the system (see Service documentation). The right way to implement this is using Alarm Manager as discussed in Android service stops.

    0 讨论(0)
  • 2020-12-14 19:12

    Will you try this:

    helloservice.setComponent(new ComponentName
                     (*hello service package name goes here*, 
                                    *hello service canonical name goes here*));
    startService(helloservice);
    
    0 讨论(0)
  • 2020-12-14 19:15

    Declare the your service in mainfest.xml file of your project.

    <services  android:name=".SMSReceiver" android:enabled="true">
              <intent-filter>
                      <action android:name=/>
             </intent-filter>
     </services>
    
    0 讨论(0)
  • 2020-12-14 19:15

    You need to implement onStartCommand()

    http://developer.android.com/reference/android/app/Service.html#onStartCommand(android.content.Intent,int,int)

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