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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:21:00+00:00 2026-06-14T22:21:00+00:00

I have made a thread for certain process, and I am running this thread

  • 0

I have made a thread for certain process, and I am running this thread with Progress Dialog simultaneously. when process complete, Progress Dialog will dismiss. until this there is no problem but when user will press back button of phone two times, activity will destroy and my process should be stop. so I have stopped thread in onDestroy(). but app is crashing at mt.stop() my code and error log is as bellow. please give me any solution and also if possible I want reason behind this.
Using flag, process will check for stop only at start of each iteration. and I want to stop process eminently.

code

Button b;
ProgressDialog pd = null;
MyThread mt;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    b = (Button) findViewById(R.id.btn_start);
    b.setOnClickListener(this);
}

public void onClick(View v) {
    pd = ProgressDialog.show(this, "one", "two", true, true);
    mt = new MyThread();
    mt.start();
}

class MyThread extends Thread {
    @Override
    public void run() {
        // assume this loop is my process.
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Log.v("log_tag", "" + i);
        }
        Log.v("log_tag", "process COmplited");
        pd.dismiss();
        super.run();
    }
}

@Override
protected void onDestroy() {
    Log.v("log_tag", "OnDestroy");
    pd.dismiss();
    mt.stop();
    super.onDestroy();
}

error in log cat;

11-09 17:26:45.313: E/global(594): Deprecated Thread methods are not supported.
11-09 17:26:45.313: E/global(594): java.lang.UnsupportedOperationException
11-09 17:26:45.313: E/global(594):  at java.lang.VMThread.stop(VMThread.java:85)
11-09 17:26:45.313: E/global(594):  at java.lang.Thread.stop(Thread.java:1379)
11-09 17:26:45.313: E/global(594):  at java.lang.Thread.stop(Thread.java:1344)
11-09 17:26:45.313: E/global(594):  at com.example.threaddemo.MainActivity.onDestroy(MainActivity.java:53)
11-09 17:26:45.313: E/global(594):  at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3642)
11-09 17:26:45.313: E/global(594):  at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3673)
11-09 17:26:45.313: E/global(594):  at android.app.ActivityThread.access$2900(ActivityThread.java:125)
11-09 17:26:45.313: E/global(594):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
11-09 17:26:45.313: E/global(594):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 17:26:45.313: E/global(594):  at android.os.Looper.loop(Looper.java:123)
11-09 17:26:45.313: E/global(594):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-09 17:26:45.313: E/global(594):  at java.lang.reflect.Method.invokeNative(Native Method)
11-09 17:26:45.313: E/global(594):  at java.lang.reflect.Method.invoke(Method.java:521)
11-09 17:26:45.313: E/global(594):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-09 17:26:45.313: E/global(594):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-09 17:26:45.313: E/global(594):  at dalvik.system.NativeStart.main(Native Method)
  • 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-14T22:21:02+00:00Added an answer on June 14, 2026 at 10:21 pm

    Please refer my solution at:
    android kill specific thread on action bar event

    The solution of using a TimerTask instead of the thread can server your purponse better and more optimized.

    Even the cancellation would work 🙂

    P.S: It also has information why stop is not working for you.

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

Sidebar

Related Questions

I posted a thread about this earlier and have made some progress but now
I have made two thread running together with Netbeans and i want to add
I have made an application for IPad in objective C. In this I am
I've started my own thread on this question so as to have less overhead
I have a small class what I made thread safe with the [Synchronization] attribute,
I have made a multi-threading program. In it, the main thread starts 10 threads
I have made an Intensity meter in a pictureBox. For making this intensity meter
I have made a small swing application for my personal use. This app connects
I have a process that will be called rather frequently from cron to read
I have made my own filetype (.mmd). This filetype i have saved some data

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.