I have a service that I would like to start with BOOT COMPLETE
when it is running, a message appears with a toast.
my problem is that when the device boots up, the toast is displayed and gets stuck on the screen, and the service does not start correctly.
however, if I try to start my service using an action, the service starts well and the toast disappears correctly after a few seconds.
my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tfl.extprotocolservice" android:versionCode="7" android:versionName="1.6" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_SETTINGS"/> <application android:allowBackup="true" android:icon="@drawable/launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <receiver android:name="com.tfl.extprotocolservice.ExtProtocolBroadcastReceiver" android:enabled="true" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <service android:name=".ExtProtocolService" > <intent-filter> <action android:name="com.tfl.extprotocolservice.ISetIpPort" /> </intent-filter> <intent-filter> <action android:name="com.tfl.extprotocolservice.IExtMessage" /> </intent-filter> </service> </application> </manifest>
my broadcast receiver:
public class ExtProtocolBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent StartServiceIntent=new Intent(context,ExtProtocolService.class); context.startService(StartServiceIntent); } }
btw, the activity in the manifest is commented out because I really don't need it, just need to check if the service starts from the activity.
source share