If you are referring to infinite loop then want to pause the running thread on it.
you may refer to this SO url.

http://stackoverflow.com/questions/7226532/android-is-performance-wise-to-implement-a-continuing-loop-with-pauseresume-fun

here's the idea:
/**
 * Call this on pause.
 */
public void pause() {
    Log.i(LOG_LOGCAT_TAG, "pause() called");
    synchronized (_mPauseLock) {
        _mPaused = true;
    }
}

/**
 * Call this on resume.
 */
public void resume() {
    Log.i(LOG_LOGCAT_TAG, "resume() called");
    synchronized (_mPauseLock) {
        _mPaused = false;
        _mPauseLock.notifyAll();
    }
}

protected void onHandleIntent(Intent arg0) {
    Log.i(LOG_LOGCAT_TAG, "loop started");
    while (!_mFinished) {
        // do stuff here

        synchronized (_mPauseLock) {
            while (_mPaused) {
                try {
                    Log.i(LOG_LOGCAT_TAG, "loop paused");
                    _mPauseLock.wait();
                    Log.i(LOG_LOGCAT_TAG, "loop resumed");
                } catch (InterruptedException e) {
                    Log.e(LOG_LOGCAT_TAG, "error occured on pause", e);
                }
            }
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Log.e(LOG_LOGCAT_TAG, "error occured on sleep", e);
        }
    }
    Log.i(LOG_LOGCAT_TAG, "loop ended");
}


(2011/10/04 11:12), Indicator Veritatis wrote:
But why would you want to suspend the thread? There is a good reason
for the deprecation of the Thread.suspend() API: you make it too hard
to avoid deadlock if you use it. Just let the scheduler do its job.

On Oct 1, 8:42 pm, bob<[email protected]>  wrote:
How do you suspend a Thread on Android?  I have a background thread,
and I need to write the onPause method.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to