Android – Start service on boot

Well here is a complete example of an AutoStart Application

AndroidManifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    package="pack.saltriver" android:versionCode="1" android:versionName="1.0">

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">

        <receiver android:name=".autostart">
                <action android:name="android.intent.action.BOOT_COMPLETED" />

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

public class autostart extends BroadcastReceiver 
    public void onReceive(Context context, Intent arg1) 
        Intent intent = new Intent(context,service.class);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        } else {
        Log.i("Autostart", "started");

public class service extends Service
    private static final String TAG = "MyService";
    public IBinder onBind(Intent intent) {
        return null;
    public void onDestroy() {
        Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
        Log.d(TAG, "onDestroy");

    public void onStart(Intent intent, int startid)
        Intent intents = new Intent(getBaseContext(),hello.class);
        Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
        Log.d(TAG, "onStart");
} – This will pop-up everytime you start the device after executing the Applicaton once.

public class hello extends Activity 
    public void onCreate(Bundle savedInstanceState) 
        Toast.makeText(getBaseContext(), "Hello........", Toast.LENGTH_LONG).show();

Leave a Comment