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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:18:28+00:00 2026-06-07T23:18:28+00:00

I have destroyed my activity by calling finish().But the thread in the activity is

  • 0

I have destroyed my activity by calling finish().But the thread in the activity is still running after destroying the activity and it causes application crash..
How can I handle this?Why the thread runs after destroying the activity?
Please provide some help?

class DBThread extends Thread {

    @Override
    public void run() {
        while (finish) {
            Cursor cursor = null;

            Cursor mCursor = lrDB.selectUserDetails(mUser_Id);
            if (mCursor.getCount() > 0) {
                mCursor.moveToNext();
                String Name = mCursor .getString(0);
                String userName = mCursor .getInt(1);
                String password = mCursor .getString(3);

            }
            mCursor.close();

        }
    }
}
  • 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-07T23:18:30+00:00Added an answer on June 7, 2026 at 11:18 pm

    First correct your thread:

    class DBThread extends Thread { 
        @Override 
        public void run() { 
            while (!isInterrupted()) {
                Cursor mCursor = lrDB.selectUserDetails(mUser_Id); 
                if (mCursor.getCount() > 0) { 
                    mCursor.moveToNext(); 
                    String Name = mCursor .getString(0); 
                    String userName = mCursor .getInt(1); 
                    String password = mCursor .getString(3); 
    
                } 
                mCursor.close(); 
            } 
        } 
    } 
    

    Secondly to close thread gracefuly do something like that in activity:

    @Override
    public void onDestroy() {
        if (yourThread!=null) {
            yourThread.interrupt(); // request to terminate thread in regular way
            yourThread.join(500); // wait until thread ends or timeout after 0.5 second
            if (yourThread.isAlive()) {
                // this is needed only when something is wrong with thread, for example hangs in ininitive loop or waits to long for lock to be released by other thread.
                Log.e(TAG, "Serious problem with thread!");
                yourThread.stop();
            }
        }
        super.onDrestroy();
    }
    

    Note that Thread.destroy() is deprecated and will not work.

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

Sidebar

Related Questions

I have a application whereby a user can destroy other users attached to the
In my application, I have an activity play http live streaming video in landscape
I read a lot about handling rotation in android applications, but I still have
I have an activity that starts a long-running service which in turn adds an
I have an activity that may have threads running when the user presses back
I have a puzzle game where pieces are dragged around the screen but can
I have the following situation I spawn a long running user thread ( Thread
I have an Activity , which starts a Thread to do some work. What
I have an object which needs to destroy itself. Can it be done? Is
I have an activity defined as below: <activity android:name=com.example.ui.HomeActivity android:alwaysRetainTaskState=true/> A strange thing is

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.