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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:18:53+00:00 2026-05-30T05:18:53+00:00

am trying to pause a thread and then resume it but when i do

  • 0

am trying to pause a thread and then resume it but when i do the pause it freeze the application. i try several things but with no luck.
on my main activity am calling the thread and have the button that will pause the thread and a second runnable class it start running and draw on my plot which include and the pause function. the code that i implement is the follow

Main activity

            public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);

         mDoctorDynamicXYDatasource= new DoctorDynamicXYDatasource(this, mHandler);
       findViewById(R.id.Pause).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) { 
                 synchronized(pp){
                    mDoctorDynamicXYDatasource.Pause();
                Log.i("File", "Pause button ");
                    }
                }   
    });
    findViewById(R.id.Start).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) { 
           draw();
         }
    });


    public void draw(){

       ///some code
       pp= new Thread(data);
         pp.start();
    }

and on the **DoctorDynamicXYDatasource class** am doing the follow

  public class DoctorDynamicXYDatasource extends Activity implements Runnable {

   public void run() {
         //loading and draw on the plot
          }

  public void Pause() {
        synchronized (Thread.currentThread()) {
         Log.i("File","pause");
                try {
                Thread.currentThread().wait();
            } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            }
        }

    }

how can i pause the thread and then start it again. when i pause the thread it lock instead only the draw plot all the screen and the button without be able to make a selection

EDIT

i add the code that you tell me and from the main activity with the pause button am calling the pause fuinction from my DoctorDynamicXYDatasource class but it’s not synchronized in order to wait the thread. am also not allow to call the pause function from other class?

mDoctorDynamicXYDatasource= new DoctorDynamicXYDatasource(this, mHandler);
         findViewById(R.id.Pause).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) { 

                    Log.i("File", "Pause button pressed");
    mDoctorDynamicXYDatasource.pause();

                }
            });
  • 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-30T05:18:54+00:00Added an answer on May 30, 2026 at 5:18 am

    You are calling pause on the UI thread, which indeed results in freezing the application.

    you have to pause your specific thread from the inside, like this:

    public void run() {
        // Your code here, there is probably a loop
        while (someCondition) {
            // Loop work
            synchronized(this) {
                if (pause) {
                    pause = false;
                    wait();
                }
            }
        }
    }
    
    public synchronized void pause() {
        pause = true;
    }
    
    public synchronized void go() {
        notify();
    }
    

    Calling pause will allow the thread to wait at the next iteration. Calling go will allow the thread to exit the wait state immediately.

    Afaik, there is no way to force a Thread to pause unless you are in the thread.

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

Sidebar

Related Questions

I am trying to run a Thread to parse a list of links using
Trying to parse some XML but apparently this is too much for a lazy
I'm trying to parse objects to XML in Delphi, so I read about calling
I'm trying to write a game engine in Android, but I don't have much
Trying to tail / parse some log files. Entries start with a date then
I'm trying to make a list of pointers to a structure called thread. Here
As the title suggests I've been trying to trigger a onmousedown even and then
Originally, I had a MediaPlayer mPlayers to play/pause/stop my Audio file. Now, I'm trying
I am trying to add pause functionality to a game. Unfortunately the method I'm
I'm trying to use core data in a multi thread way. I simply want

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.