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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:26:05+00:00 2026-05-26T07:26:05+00:00

In one Activity, I define the following Button listener: final Button button = (Button)

  • 0

In one Activity, I define the following Button listener:

final Button button = (Button) findViewById(R.id.buttonExit);
button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        stopService(new Intent(StartupActivity.this, SamcomService.class));
        finish();
    }
});

As you can see, the button is supposed to stop the running Service (created in a previous step), and then finish itself.

When I press the button, the Service.onDestroy is executed just as expected. In the onDestroy I do some cleaning, and then lastly call super.onDestroy():

 @Override
 public void onDestroy() {   // the service onDestroy

     // Do some cleaning

     NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
     mNotificationManager.cancel(1);

     // more cleaning
     Toast.makeText(this, "The service has been stopped! Wii!", Toast.LENGTH_LONG).show();
      super.onDestroy();
 }

Im my world, that means this Service is dead and buried, along with all the variables in it. Right?
Well, it doesnt seem like it.

The think is, I have a String in my Service that I append text to before I click the button to stop the service. Something like this:

public class SamcomService extends Service {

    private String startupText = "";

    private void addTextToStartup(String text)
    {
        startupText += text;

        // Sending a broadcast, not relevant
        // ...
    }

    // ...
}

That string, startupText, is not reset when I launch my app again! Its like the Service wasn’t killed at all. The startupText contains all the text that was added to it in the previous run.

Why is that? What am I missing? Isnt the Service dead? When I launch the app again, the Service onCreate method is called, implying that it is started from scratch…

— EDIT —

I just read this:
What exactly does onDestroy() destroy?

That means that the onDestroy doesnt really destroy anything. Correct? Its pretty lame, and extremely annoying. One well-visited thread here on SO that I create almsot 2 years ago discussing this issue I guess…:
Is quitting an application frowned upon?

  • 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-26T07:26:06+00:00Added an answer on May 26, 2026 at 7:26 am

    So, as I wrote in my EDIT above:

    I just read this: What exactly does onDestroy() destroy?

    That means that the onDestroy doesnt really destroy anything. Correct? Its pretty lame, and extremely annoying. One well-visited thread here on SO that I create almsot 2 years ago discussing this issue I guess…: Quitting an application – is that frowned upon?

    However, I solved my problem a way that of course everyone will say “noooo!” to. However, it works nicely. I simply put System.exit(0) in my onDestroy-method in the Service. No more lingering variables =)

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

Sidebar

Related Questions

I've already written some small Android Applications, most of them in one Activity and
I have to include one report in my application showing offline/online activity of few
I am new to Android development and have been following the tutorials available on
I have an @activity that has_many :clientships When creating a new object I assign
My application's main Activity is a TabActivity and it contains an OptionsMenu. I define
hi im new to android i have added defined login screen in one screen
I have an Activity MyActivity with a Button MyButton . I want to attach
I was wondering what happened if I define a base Activity object with all
I want to define just one row in my table. To this row, I
One of those classic programming interview questions... You are given two marbles, and told

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.