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 7669115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:31:24+00:00 2026-05-31T15:31:24+00:00

How do you create a Service that keeps on running when your application is

  • 0

How do you create a Service that keeps on running when your application is stopped? I am creating the service in a separate process in the manifest file:

<service
    android:name="com.example.myservice"
    android:process=":remoteservice" />

I am also returning START_STICKY in the Service’s onStartCommand:

@Override
public in onStartCommand(Intent intent, int flags, int startId){
    return Service.START_STICKY;
}
  • 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-05-31T15:31:25+00:00Added an answer on May 31, 2026 at 3:31 pm

    I wouldn’t use the android:process attribute – this actually runs your service in a separate process and makes it hard to do things like share preferences. You won’t have to worry about your service dying when your application dies, the service will keep going (that is the point of a service). You also don’t want a binding service because that will start and die when the bindings do. That being said:

    <service
        android:enabled="true"
        android:exported="true"
        android:name=".MyService"
        android:label="@string/my_service_label"
        android:description="@string/my_service_description"
        <intent-filter>
            <action android:name="com.package.name.START_SERVICE" />
        </intent-filter>
    </service>
    

    You can define your own action for the intent to launch the service (cannot be launched by the system – has to be an activity). I like to set “enabled” to true so the system can instantiate my service, and “exported” so other applications can send intents and interact with my service. You can find more about this here.

    You can also make a long running service that uses bindings, if you do this just add and intent for the binder such as:

    <action android:name="com.package.name.IRemoteConnection" />
    

    Now to start the service from your activity:

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            Intent serviceIntent = new Intent("com.package.name.START_SERVICE");
            this.startService(serviceIntent);
    
            // You can finish your activity here or keep going...
        }
    }
    

    Now for the service:

    public class MyService extends Service {
    
        @Override
        public IBinder onBind(Intent intent) {
            // This is triggered by the binder action intent.
            // You can return your binder here if you want...
            return null;
        }
    
    
        @Override
        public void onCreate() {
            // Called when your service is first created.
        }
    
        @Override
        public in onStartCommand(Intent intent, int flags, int startId) {
            // This is triggered by the service action start intent
            return super.onStartCommand(intent, flags, startId);
        }
    }
    

    Now your service should run. To help with the longevity there are some trick. Make it run as a foreground service (you do this in the service) – this will make you create a notification icon that sticks in the status bar. Also keep your HEAP light to make you application less likely to be killed by Android.

    Also the service is killed when you kill the DVM – thus if you are going to Settings->Applications and stopping the application you are killing the DVM and thus killing the service. Just because you see your application running in the settings does no mean the Activity is running. The activity and service have different life-cycles but can share a DVM. Just keep in mind you don’t have to kill your activity if not needed, just let Android handle it.

    Hope this helps.

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

Sidebar

Related Questions

I need to create a service that will be called back by a third
I need to create a service that monitor sms received and sent. The only
I have a WCF service that works ok if I create the service without
Here is what I have in mind: 1) Create a service that will run
Anybody knows how to do this? I need to create a service that will
We are trying to create a web-service that we plan to pass a variable
I am trying create a WCF service that leverages the WPF MediaPlayer on the
I am trying to create an OSGi service that wraps another jar. I added
Hi I want to create a WCF service that have login method, which is
i'd like to create a windows service that would be accessible via WCF from

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.