Can I start a service without activity or receiver?

前端 未结 2 1430
执笔经年
执笔经年 2020-12-17 23:00

I want to start a service in an APK.

I tried to use as following:



        
相关标签:
2条回答
  • 2020-12-17 23:24

    You can write a BroadcastReceiver and run the Service after receiving the Intent. For example after device boot-up or other Intent that you need.

    <receiver android:name=".StartupReceiver">
       <intent-filter>
         <action android:name="android.intent.action.BOOT_COMPLETED"/>
         <category android:name="android.intent.category.HOME"/>
       </intent-filter>
    </receiver>
    
    0 讨论(0)
  • 2020-12-17 23:26

    No you can't.

    Create a simple Activity which starts the service and simply provides some feedback to the user (to tell them the service has started for example) and set that Activity with the MAIN/LAUNCHER intent.

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