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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:21:18+00:00 2026-05-21T03:21:18+00:00

Normally, when I close my app I send an intent to my service to

  • 0

Normally, when I close my app I send an intent to my service to signal to safely shutdown using onStartCommand with an extra boolean of true. I do this in my application class’ onTerminate. I added the if statements because I was getting a nullptrexception when force closing the app in this block.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        boolean state = intent.getBooleanExtra("terminate", false);
        mSafeShutdown = state;
    }
    else if (mUpdater != null && mUpdater.isRunning()) {
        Log.d(TAG, "activity force closed?" + 
            " Attempting to handle service thread shutdown safely...");
        mUpdater.isRunning(false);
        try {
            mUpdater.join();
        } catch (InterruptedException e) {
            Log.e(TAG,"Service's UpdaterThread couldn't join");
        }
    }
    return START_STICKY;
}

however, this causes my service to stay alive –

static final int DELAY = 2000;
public void run() {
    while (mIsRunning) {
        if (!mJobQueue.isEmpty()) {
            //do work
        }
        else if (mSafeShutdown) {
            mIsRunning = false;
            stopSelf();
        }
        else {
            sleep(DELAY);
        }
    }
}

The fact that force closing disconnects the debugger its making hard to see exactly whats going on.. Is there a better/safer way to tell my service thread that the application has shut down?

  • 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-21T03:21:18+00:00Added an answer on May 21, 2026 at 3:21 am

    since your thread is a child class, create a method in it to shut it down the thread and call it in your parent class.

    An example can be found here
    http://download.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html

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

Sidebar

Related Questions

When typing code, I would normally close brackets, go back inside, go outside, type
Normally you make a call to a service, it blocks until a thread in
Normally, if I want to start a new activity I can use StartActivity(typeof(foo)); This
Normally the XML files I have to parse are like this: <row id=1> <title>widget<title>
Normally we use window.location.href=/index.php?querystring; in javascript. Is there a way to send the querystring
I'm using Apache Derby with the Spring JdbcTemplate inside a web app running on
I have an app written in c# using nhibernate with an sqlite DB. For
I'm putting together a new app and, while I normally use JQuery for things
Normally when I use backbone.js I would apply this sort of patch to nest
I'm building some kind of indefinite filters for an app, and I'm havin this

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.