Q:

how to pause and stop a changing ImageView

i have an ImageView in which the picture switches every 5s, i am trying to add a pause and 
resume button that can stop and restart the action.  i am using a Handler, Runnable, and 
postDelay() for image switch, and i put the code on onResume.  i am thinking about using 
wait and notify for the pause and resume, but that would mean creating an extra thread.  so 
far for the thread, i have this:
class RecipeDisplayThread extends Thread 
    {
        boolean pleaseWait = false;
    // This method is called when the thread runs
    public void run() {
        while (true) {
            // Do work

            // Check if should wait
            synchronized (this) {
                while (pleaseWait) {
                    try {
                        wait();
                    } catch (Exception e) {
                    }
                }
            }

            // Do work
        }
    }

}   

and in the main activity's onCreate():
        Button pauseButton = (Button) findViewById(R.id.pause);

        pauseButton.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View view) 
            {
                while (true) {

                synchronized (thread) 
                {
                    thread.pleaseWait = true;
                    }
                }

            }
        });

        Button resumeButton = (Button) findViewById(R.id.resume);

        resumeButton.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View view) 
            {
                while (true) {

                // Resume the thread
                synchronized (thread) 
                {
                    thread.pleaseWait = false;
                    thread.notify();
                }
                }

            }
        });

the pause button seems to work, but then after that i can't press any other button, such as 
the resume button.
thanks.

A:

i am using a Handler, Runnable, and
  postDelay() for image switch

Why? Why not use postDelayed() and get rid of the Thread and Handler?
  void doTheImageUpdate() {
    if (areWeStillRunning) {
      myImageView.setImageResource(R.drawable.whatever);
      myImageView.postDelayed(updater, 5000);
    }
  }

  Runnable updater=new Runnable() {
    public void run() {
      doTheImageUpdate();
    }
  };

When you want to start updating, set areWeStillRunning to true and call doTheImageUpdate(). When you want to stop updating, set areWeStillRunning to false. You'll need to work out the edge case of where the user presses pause and resume within 5 seconds, to prevent doubling things up, but I leave that as an exercise for the reader.
If you really want to use a background thread, you will want to learn more about how to use background threads. For example, while(true) {} without any form of exit will never work. There are some good books on the subject, such as this one.

