Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8705601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:24:16+00:00 2026-06-13T03:24:16+00:00

I am trying to start a foreground service at boot time, but it never

  • 0

I am trying to start a foreground service at boot time, but it never starts, however If i try to start a normal background service. It starts perfectly fine.

Can you please let me what is wrong with my code ?

My code is:
Manifest file:

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <receiver android:name="com.test.andsrvfg.AndSrvFgService">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <service android:name="AndSrvFgService">
        <intent-filter>
            <action android:name="com.test.andsrvfg.AndSrvFgService"></action>
        </intent-filter>
    </service>
</application>

BroadcastReceiver to handle ACTION_BOOT_COMPLETED:

public class AndSrvFgStarter extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Intent i = new Intent();
            i.setAction("com.test.andsrvfg.AndSrvFgService");
            context.startService(i);
        }
    }
}

The actual service is like:

public class AndSrvFgService extends Service {

    private boolean bForeground = false;
    public AndSrvFgService() {
    }

    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if(!bForeground) {
            bForeground = true;
            Notification note = new Notification( 0, null, System.currentTimeMillis() );
            note.flags |= Notification.FLAG_NO_CLEAR;
            startForeground( 1242, note );      
                }


        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        if(bForeground) {
            stopForeground(true);
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:24:17+00:00Added an answer on June 13, 2026 at 3:24 am

    This code works for me:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.dfsdf"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="15" />
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".MainActivity"
                android:label="@string/title_activity_main" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
            <activity android:name="com.google.ads.AdActivity"
                  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    
            <service android:name=".MyService"/>
    
            <receiver android:enabled="true" 
                android:name=".BootUpReceiver"
                android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
                <intent-filter >
                    <action android:name="android.intent.action.BOOT_COMPLETED"/>
                    <category android:name="android.intent.category.DEFAULT"/>
                </intent-filter>
            </receiver>
    
        </application>
    
    </manifest>
    
    • Put this in the receiver:

      android:permission=”android.permission.RECEIVE_BOOT_COMPLETED”

    • Set enable to true:

      android:enabled=”true”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to start service from AsyncTask but cant see that its starts.
I'm trying to start emulator-arm but it seems to get stuck and never shows
I'm trying to start a service as a user and things work fine, until
I'm trying to start a phantomjs process from python but for some reason it's
I am trying to start a new Rails project but I am getting a
i'm trying to achieve a functionality but i'm don't know how to start it.
I'm trying start java application but in browser i see standard tomcat's page. Server
I'm trying to start an AlertDialog from an onClickListener but I'm getting the following
I am trying to start activity at start up of phone but whole program
I'm trying to start a test server via ssh but it always dies once

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.