Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I start a service without activity or receiver?

I want to start a service in an APK.

I tried to use as following:

<application android:icon="@drawable/icon" android:label="@string/app_name">  
        <service android:name =".TestServcie">  
            <intent-filter>  
                <action android:name="android.intent.action.MAIN" />  
                <category android:name="android.intent.category.LAUNCHER" />  
            </intent-filter>  
        </service>  
    </application>

Any ideas?
Thanks

like image 596
Sean Avatar asked Dec 17 '10 05:12

Sean


1 Answers

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>
like image 166
mysuperass Avatar answered Oct 15 '22 06:10

mysuperass