how to pause and stop a changing ImageView
<p>i have an ImageView in which the picture switches every 5s, i am trying to add a pause and </p>

<p>resume button that can stop and restart the action.  i am using a Handler, Runnable, and </p>

<p>postDelay() for image switch, and i put the code on onResume.  i am thinking about using </p>

<p>wait and notify for the pause and resume, but that would mean creating an extra thread.  so </p>

<p>far for the thread, i have this:</p>

<p>class RecipeDisplayThread extends Thread 
    {
        boolean pleaseWait = false;</p>

<pre><code>    // 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
        }
    }

}   
</code></pre>

<p>and in the main activity's onCreate():</p>

<pre><code>        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();
                }
                }

            }
        });
</code></pre>

<p>the pause button seems to work, but then after that i can't press any other button, such as </p>

<p>the resume button.</p>

<p>thanks.</p>
