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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:18:22+00:00 2026-05-26T06:18:22+00:00

I am trying to figure out how Android works when it comes to lifecycle

  • 0

I am trying to figure out how Android works when it comes to lifecycle issues.

I have decided to have a long-running Service to hold my TCP-connections and other stuff.

I have one Activity, StartupActivity. That Activity starts a service, and then I press a button to Finish the Activity. I then launch the same app/Activity again, and thus the startService is executed again.

However, I expected the Service to still be alive (there has been no onDestroy called), but the onCreate-method in the Service is still being executed.

Why?

STEP 1: onCreate in StartupActivit is executed:

@Override
protected void onCreate(android.os.Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.startup);

    startService(new Intent(StartupActivity.this, SamcomService.class));
    registerReceiver(connectionReceiver, new IntentFilter("STARTUP_PROGRESS_MESSAGE"));
    registerReceiver(connectionReceiver, new IntentFilter("STARTUP_FINISH"));

    final Button button = (Button) findViewById(R.id.buttonExit);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            finish();
        }
    });
}

STEP 2: I press the button, and Activity.finish() is called (I am returned to the home screen)

STEP 3: I launch the app again, and the onCreate for the Activity is once more executed, thus starting the same Service

Now, when I start the app the second time the Service should be running (how do I check that?). I havent seen the Toast that is displayed when the Service onDestroy is called, and I also see the Notification that the Service creates (and removes onDestroy).

However, the onCreate is executed a second time. Do I now have more than one Service running at the same time?

  • 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-26T06:18:23+00:00Added an answer on May 26, 2026 at 6:18 am

    However, the onCreate is executed a second time. Do I now have more than one Service running at the same time?

    No, and I know this is confusing, but the startService() method does not start the service. It will be called in the service everytime you run it. For instance, if the service isn’t started, it will start it and then run it. If the service is started, it will just run it. The android documentation says it was designed this way so that the startService() method is the easiest way to communicate with your service.

    STEP 2: I press the button, and Activity.finish() is called (I am returned to the home screen)

    This depends on if your service is running on the same process as your activity or not. If you have :process = “something” in your service declaration in the manifest, and you did everything else perfectly, the service is in another process and there are only three situiations inwhich your service will be destroyed. 1, your activity is destroyed(Almost guaranteed not to happen as your process has its activities active priority), 2, There is EXTREMELY low memory, 3 the service calls selfStop().

    Since finish() does not destroy your app(Android keeps it around in memory encase the user comes back to it), your service is either just paused(If it was in the same process) or still running(If it was in a different process). Regardless another call to startService() will restart it if it was paused and run the service’s startService method. You only ever have one of your services around.

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

Sidebar

Related Questions

I'm working on a client-server Android application and trying to figure out how to
Trying to figure out why my vertex shader works on my cell phone (Casio
I've spent several days trying to figure out what is wrong with my android
I am a starter on Android and trying to figure out how do use
I have spend about 3 hours trying to figure this out and it seems
I'm trying to figure out how to POST JSON from Android by using HTTPClient.
I'm very new to an Android platform and currently trying figure out why things
Trying to figure out an equation to get the current group a page would
Trying to figure out the best way to set up collection lists for users
Trying to figure out which to use.

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.