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

  • Home
  • SEARCH
  • 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 9044669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:02:40+00:00 2026-06-16T11:02:40+00:00

I want to start only to start a service when my application start. Here

  • 0

I want to start only to start a service when my application start. Here is my code:

My Service class:

public class MyService extends Service {
 @Override
  public int onStartCommand(Intent intent, int flags, int startId) {

     Log.i("LocalService", "Received start id " + startId + ": " + intent);

   // We want this service to continue running until it is explicitly
   // stopped, so return sticky.
   return START_STICKY;
  }

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}
}

My BroadcastReceiver class:

public class MyServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Intent service = new Intent(context, MyService.class);
    context.startService(service);
}
}

And my AndroidManifest file:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <service
      android:name=".MyService"
      android:label="@string/app_name"
      android:enabled="true"
      android:process=":my_process" >
    </service>

    <receiver 
        android:name=".MyServiceReceiver"
        android:enabled="true" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
            <category android:name="android.intent.category.HOME"/>
        </intent-filter>
    </receiver>

</application>

I want to start my service when the application start (is installed the first time) and when the device boot.

P.S. If the code is right, maybe I have to setup a particular configuration for the eclipse “run” button? If try to create a new configuration I can’t select nothing in “Launch action” because my application haven’t an activity, and I have to select “Do nothing”.

Thanks

  • 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-16T11:02:41+00:00Added an answer on June 16, 2026 at 11:02 am

    You’re going to need a main activity to call this service within onCreate if you want the service to start as soon as you start your application. In your main activity, include this code in your onCreate:

    startService(new Intent(Main_Activity.this,MyServiceReceiver.class));

    This is just to call your service when you start up your application.

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

Sidebar

Related Questions

I want to execute some code only once on start of a web service.
I want to make regular expression that start with only 4 and 5 and
So I want to position an element across two columns, but only start in
Let me start off by saying I don't want to print only the duplicate
I have a situation like this: start(); <Some code> end(); I want start() function
I want to start manage application ( Settings -> Application -> manage application ->
My application start foreground service witch keep connection to server. It's show notification with
I start an activity in my class Locator.java which starts a locacionListener Service. That
I need to get elevated credentials (to start a service) in a VB6 application,
I want to start several threads, retrive data from net, perform some actions with

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.