下面列出了android.os.Looper#quit ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
public static void quitSafely(final Looper looper) {
if (null != METHOD_quitSafely) {
CompatUtils.invoke(looper, null /* default return value */, METHOD_quitSafely);
} else {
looper.quit();
}
}
public boolean quit() {
Looper looper = getLooper();
if (looper == null) {
return false;
}
looper.quit();
return true;
}
@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;
}
}
@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;
}
}
public void quit() throws IllegalStateException {
final Looper looper = getLooper();
if (looper != null) {
looper.quit();
} else {
throw new IllegalStateException("has no looper");
}
}
@Override
protected void finalize() throws Throwable {
looper.join(100);
Handler h = looper.mHandler;
Looper l = h.getLooper();
l.quit();
looper.join();
super.finalize();
}
public static void quitSafely(final Looper looper) {
if (null != METHOD_quitSafely) {
CompatUtils.invoke(looper, null /* default return value */, METHOD_quitSafely);
} else {
looper.quit();
}
}
@Override
public void run() {
Looper looper = Looper.myLooper();
if (looper != null) {
looper.quit();
}
}
public void destroy() {
abort();
Looper looper = mScanThread.getLooper();
looper.quit();
}
/**
* 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;
}