Java Code Examples for android.os.Looper#quit()

The following examples show how to use android.os.Looper#quit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BarCodeProcessor.java    From StarBarcode with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleMessage(Message msg) {

    BarCodeProcessor barCodeProcessor = weakReference.get();
    if (barCodeProcessor == null) return true;
    if (msg == null || !barCodeProcessor.running) return true;

    switch (State.values()[msg.what]){
        case DECODE:
            barCodeProcessor.decodeFrame((byte[]) msg.obj, msg.arg1, msg.arg2);
            break;
        case QUIT:
            barCodeProcessor.running = false;
            Looper looper = Looper.myLooper();
            if (looper != null) {
                looper.quit();
            }
            break;
    }
    return true;
}
 
Example 2
Source File: LooperCompatUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
public static void quitSafely(final Looper looper) {
    if (null != METHOD_quitSafely) {
        CompatUtils.invoke(looper, null /* default return value */, METHOD_quitSafely);
    } else {
        looper.quit();
    }
}
 
Example 3
Source File: DownloadEngine.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean quit() {
    Looper looper = getLooper();
    if (looper == null) {
        return false;
    }
    looper.quit();
    return true;
}
 
Example 4
Source File: DecodeHandler.java    From Tesseract-OCR-Scanner with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message message) {
    switch (message.what) {
        case R.id.decode:
            decode((byte[]) message.obj, message.arg1, message.arg2);
            break;
        case R.id.quit:
            Looper looper = Looper.myLooper();
            if (null != looper) {
                looper.quit();
            }
            break;
    }
}
 
Example 5
Source File: DecodeHandler.java    From QrCodeScanner with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleMessage(Message message) {
    switch (message.what) {
        case R.id.decode:
            decode((byte[]) message.obj, message.arg1, message.arg2);
            break;
        case R.id.quit:
            Looper looper = Looper.myLooper();
            if (null != looper) {
                looper.quit();
            }
            break;
    }
}
 
Example 6
Source File: HandlerThreadHandler.java    From libcommon with Apache License 2.0 5 votes vote down vote up
public void quit() throws IllegalStateException {
	final Looper looper = getLooper();
	if (looper != null) {
		looper.quit();
	} else {
		throw new IllegalStateException("has no looper");
	}
}
 
Example 7
Source File: TodoApplicationTest.java    From endpoints-codelab-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void finalize() throws Throwable {
    looper.join(100);
    Handler h = looper.mHandler;
    Looper l = h.getLooper();
    l.quit();
    looper.join();
    super.finalize();
}
 
Example 8
Source File: LooperCompatUtils.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
public static void quitSafely(final Looper looper) {
    if (null != METHOD_quitSafely) {
        CompatUtils.invoke(looper, null /* default return value */, METHOD_quitSafely);
    } else {
        looper.quit();
    }
}
 
Example 9
Source File: ThreadUtils.java    From xdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    Looper looper = Looper.myLooper();
    if (looper != null) {
        looper.quit();
    }
}
 
Example 10
Source File: PortSweeper.java    From android-vlc-remote with GNU General Public License v3.0 4 votes vote down vote up
public void destroy() {
    abort();
    Looper looper = mScanThread.getLooper();
    looper.quit();
}
 
Example 11
Source File: MoneroHandlerThread.java    From xmrwallet with Apache License 2.0 3 votes vote down vote up
/**
 * Quits the handler thread's looper.
 * <p>
 * Causes the handler thread's looper to terminate without processing any
 * more messages in the message queue.
 * </p><p>
 * Any attempt to post messages to the queue after the looper is asked to quit will fail.
 * For example, the {@link Handler#sendMessage(Message)} method will return false.
 * </p><p class="note">
 * Using this method may be unsafe because some messages may not be delivered
 * before the looper terminates.  Consider using {@link #quitSafely} instead to ensure
 * that all pending work is completed in an orderly manner.
 * </p>
 *
 * @return True if the looper looper has been asked to quit or false if the
 * thread had not yet started running.
 * @see #quitSafely
 */
public boolean quit() {
    Looper looper = getLooper();
    if (looper != null) {
        looper.quit();
        return true;
    }
    return false;
}