{"id":83,"date":"2021-04-24T22:21:00","date_gmt":"2021-04-24T14:21:00","guid":{"rendered":"https:\/\/newstrong.xyz\/?p=83"},"modified":"2021-04-24T22:21:00","modified_gmt":"2021-04-24T14:21:00","slug":"android%e5%bc%80%e5%8f%91%e4%b8%adhandler%e5%90%8c%e6%ad%a5%e5%b1%8f%e9%9a%9c%e6%9c%ba%e5%88%b6sync-barrier%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/newstrong.top\/index.php\/2021\/04\/24\/android%e5%bc%80%e5%8f%91%e4%b8%adhandler%e5%90%8c%e6%ad%a5%e5%b1%8f%e9%9a%9c%e6%9c%ba%e5%88%b6sync-barrier%e8%af%a6%e8%a7%a3\/","title":{"rendered":"Android\u5f00\u53d1\u4e2dHandler\u540c\u6b65\u5c4f\u969c\u673a\u5236(sync barrier)\u8be6\u89e3"},"content":{"rendered":"<section style=\"font-size: 16px; color: black; padding-right: 10px; padding-left: 10px; word-break: break-word; text-align: left; line-height: 1.25; letter-spacing: 2px; background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%), linear-gradient(360deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%); background-size: 20px 20px; background-position: center center; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;\" data-tool=\"mdnice\u7f16\u8f91\u5668\" data-website=\"https:\/\/www.mdnice.com\">\n<section class=\"mp_profile_iframe_wrp\"><\/section>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">Handler\u540c\u6b65\u5c4f\u969c\u673a\u5236\u662fAndroid\u5f00\u53d1\u4e2d\u4e00\u4e2a\u8f83\u4e3a\u9ad8\u7ea7\u4e14\u590d\u6742\u7684\u7279\u6027\uff0c\u4e3b\u8981\u7528\u4e8e\u63a7\u5236\u6d88\u606f\u961f\u5217MessageQueue\u4e2d\u6d88\u606f\u7684\u5904\u7406\u987a\u5e8f\u3002\u5f53\u8bbe\u7f6e\u540c\u6b65\u5c4f\u969c\u65f6\uff0c\u4f1a\u963b\u6b62\u6240\u6709\u666e\u901a\u6d88\u606f\uff08\u540c\u6b65\u6d88\u606f\uff09\u7684\u5904\u7406\uff0c\u540c\u65f6\u5141\u8bb8\u7acb\u5373\u6d88\u606f\uff08\u4f8b\u5982\u5e26\u56de\u8c03\u7684\u6d88\u606f\u6216Runnable\u5bf9\u8c61\uff09\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><strong style=\"color: #916dd5;\">\u300c\u6d88\u606f\u5206\u7c7b\u300d<\/strong>\uff1a<\/p>\n<ul class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px; font-size: 15px; list-style-type: circle;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\"><strong style=\"color: #916dd5;\">\u300c\u666e\u901a\u6d88\u606f\uff08\u540c\u6b65\u6d88\u606f\uff09\u300d<\/strong>\uff1a\u5e38\u89c1\u7684\u901a\u8fc7Handler\u53d1\u9001\u7684\u6d88\u606f\uff0c\u6309\u7167\u65f6\u95f4\u6233\u987a\u5e8f\u5728MessageQueue\u4e2d\u6392\u961f\u3002\u6211\u4eec\u5e73\u65f6\u53d1\u7684\u6d88\u606f\u57fa\u672c\u90fd\u662f\u540c\u6b65\u6d88\u606f\uff0c\u5728\u8fd9\u91cc\u4e0d\u505a\u8ba8\u8bba\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\"><strong style=\"color: #916dd5;\">\u300c\u5c4f\u969c\u6d88\u606f\uff08\u540c\u6b65\u5c4f\u969c\uff09\u300d<\/strong>\uff1a\u4e00\u4e2a\u7279\u6b8a\u7684Message\u5bf9\u8c61\uff0c\u6ca1\u6709target\u5c5e\u6027\uff0c\u7528\u4e8e\u5728MessageQueue\u4e2d\u63d2\u5165\u5c4f\u969c\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\"><strong style=\"color: #916dd5;\">\u300c\u5f02\u6b65\u6d88\u606f\u300d<\/strong>\uff1a\u53ef\u4ee5\u901a\u8fc7\u7279\u5b9a\u65b9\u5f0f\u6807\u8bb0\u7684\u6d88\u606f\uff0c\u4f18\u5148\u7ea7\u9ad8\u4e8e\u540c\u6b65\u6d88\u606f\uff0c\u5373\u4f7f\u5b58\u5728\u540c\u6b65\u5c4f\u969c\u4e5f\u80fd\u88ab\u5904\u7406\u3002<\/section>\n<\/li>\n<\/ul>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; text-align: center;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"border-bottom: 2px solid #d89cf6;\">\u5c4f\u969c\u6d88\u606f\uff08\u540c\u6b65\u5c4f\u969c\uff09<\/span><\/h3>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u540c\u6b65\u5c4f\u969c\u662f\u901a\u8fc7MessageQueue\u7684postSyncBarrier\u65b9\u6cd5\u5f00\u542f\u3002<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #ddd; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #272822; border-radius: 5px;\"><span style=\"line-height: 26px;\"><span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">private<\/span>\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">int<\/span>\u00a0<span style=\"color: #a6e22e; font-weight: bold; line-height: 26px;\">postSyncBarrier<\/span><span style=\"line-height: 26px;\">(<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">long<\/span>\u00a0when)<\/span>\u00a0<\/span>{\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0Enqueue\u00a0a\u00a0new\u00a0sync\u00a0barrier\u00a0token.<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0We\u00a0don't\u00a0need\u00a0to\u00a0wake\u00a0the\u00a0queue\u00a0because\u00a0the\u00a0purpose\u00a0of\u00a0a\u00a0barrier\u00a0is\u00a0to\u00a0stall\u00a0it.<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">synchronized<\/span>\u00a0(<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">this<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">final<\/span>\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">int<\/span>\u00a0token\u00a0=\u00a0mNextBarrierToken++;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">final<\/span>\u00a0Message\u00a0msg\u00a0=\u00a0Message.obtain();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg.markInUse();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg.when\u00a0=\u00a0when;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg.arg1\u00a0=\u00a0token;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Message\u00a0prev\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Message\u00a0p\u00a0=\u00a0mMessages;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(when\u00a0!=\u00a0<span style=\"line-height: 26px;\">0<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">while<\/span>\u00a0(p\u00a0!=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>\u00a0&amp;&amp;\u00a0p.when\u00a0&lt;=\u00a0when)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0prev\u00a0=\u00a0p;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0p\u00a0=\u00a0p.next;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(prev\u00a0!=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>)\u00a0{\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0invariant:\u00a0p\u00a0==\u00a0prev.next<\/span>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg.next\u00a0=\u00a0p;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0prev.next\u00a0=\u00a0msg;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">else<\/span>\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg.next\u00a0=\u00a0p;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mMessages\u00a0=\u00a0msg;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">return<\/span>\u00a0token;\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/code><\/pre>\n<ul class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px; font-size: 15px; list-style-type: circle;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\">\u7b2c\u4e00\u6b65\uff0c\u83b7\u53d6\u5c4f\u969c\u7684\u7684\u552f\u4e00\u6807\u793a\uff0c\u6807\u793a\u4ece0\u5f00\u59cb\uff0c\u81ea\u52a01\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\">\u7b2c\u4e8c\u6b65\uff0c\u4eceMessage\u6d88\u606f\u5bf9\u8c61\u6c60\u4e2d\u83b7\u53d6\u4e00\u4e2amsg\uff0c\u8bbe\u7f6emsg\u4e3a\u6b63\u5728\u4f7f\u7528\u72b6\u6001\uff0c\u5e76\u4e14\u91cd\u7f6emsg\u7684when\u548carg1\uff0carg1\u7684\u503c\u8bbe\u7f6e\u4e3atoken\u503c\u3002\u4f46\u662f\u8fd9\u91cc\u5e76\u6ca1\u6709\u7ed9tareget\u8d4b\u503c\u3002\u6240\u4ee5msag\u7684target\u662f\u5426\u4e3a\u7a7a\u662f\u5224\u65ad\u8fd9\u4e2amsg\u662f\u5426\u662f\u5c4f\u969c\u6d88\u606f\u7684\u6807\u5fd7\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\">\u7b2c\u4e09\u6b65\uff0c\u521b\u5efa\u53d8\u91cfpre\u548cp\uff0c\u4e3a\u4e0b\u4e00\u6b65\u505a\u51c6\u5907\u3002\u5176\u4e2dp\u88ab\u8d4b\u503c\u4e3amMessages\uff0cmMessages\u6307\u5411\u6d88\u606f\u961f\u5217\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u6240\u4ee5\u6b64\u65f6p\u6307\u5411\u6d88\u606f\u961f\u5217\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\">\u7b2c\u56db\u6b65\uff0c\u901a\u8fc7\u5bf9\u961f\u5217\u4e2d\u7684\u7b2c\u4e00\u4e2aMessage\u7684when\u548c\u5c4f\u969c\u7684when\u8fdb\u884c\u6bd4\u8f83\uff0c\u51b3\u5b9a\u5c4f\u969c\u6d88\u606f\u5728\u6574\u4e2a\u6d88\u606f\u961f\u5217\u4e2d\u7684\u4f4d\u7f6e\uff0c\u56e0\u4e3a\u6d88\u606f\u961f\u5217\u4e2d\u7684\u6d88\u606f\u90fd\u662f\u6309\u65f6\u95f4\u6392\u5e8f\u7684\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\">\u7b2c\u4e94\u6b65\uff0cprev != null\uff0c\u4ee3\u8868\u4e0d\u662f\u6d88\u606f\u7684\u5934\u90e8\uff0c\u628amsg\u63d2\u5165\u5230\u6d88\u606f\u961f\u5217\u4e2d\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\">\u7b2c\u516d\u6b65\uff0cprev == null\uff0c\u4ee3\u8868\u662f\u6d88\u606f\u961f\u5217\u7684\u5934\u90e8\uff0c\u628amsg\u63d2\u5165\u6d88\u606f\u7684\u5934\u90e8\u3002<\/section>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u901a\u5e38\u901a\u8fc7Handler\u53d1\u9001\u6d88\u606fhandler.sendMessage(),\u6700\u7ec8\u90fd\u4f1a\u8c03\u7528Handler.java\u4e2d\u7684enqueueMessage()\u65b9\u6cd5\u3002<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #ddd; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #272822; border-radius: 5px;\"><span style=\"line-height: 26px;\"><span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">private<\/span>\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">boolean<\/span>\u00a0<span style=\"color: #a6e22e; font-weight: bold; line-height: 26px;\">enqueueMessage<\/span><span style=\"line-height: 26px;\">(@NonNull\u00a0MessageQueue\u00a0queue,\u00a0@NonNull\u00a0Message\u00a0msg,\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">long<\/span>\u00a0uptimeMillis)<\/span>\u00a0<\/span>{\n\u00a0\u00a0\u00a0\u00a0msg.target\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">this<\/span>;\n\u00a0\u00a0\u00a0\u00a0msg.workSourceUid\u00a0=\u00a0ThreadLocalWorkSource.getUid();\n\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(mAsynchronous)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg.setAsynchronous(<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">true<\/span>);\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">return<\/span>\u00a0queue.enqueueMessage(msg,\u00a0uptimeMillis);\n}\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u53ef\u4ee5\u770b\u5230\uff0cenqueueMessage()\u65b9\u6cd5\u91cc\u4e3amsg\u8bbe\u7f6e\u4e86target\u5b57\u6bb5\u3002\u800cpostSyncBarrier()\u65b9\u6cd5\u4e5f\u662f\u4eceMessage\u6d88\u606f\u5bf9\u8c61\u6c60\u4e2d\u83b7\u53d6\u4e00\u4e2amsg\u63d2\u5165\u5230\u6d88\u606f\u961f\u5217\u4e2d\uff0c\u552f\u4e00\u7684\u4e0d\u540c\u662f\u6ca1\u6709\u8bbe\u7f6etarget\u5b57\u6bb5\uff0c\u4ece\u4ee3\u7801\u5c42\u9762\u4e0a\u8bb2\uff0c\u5c4f\u969c\u6d88\u606f\u5c31\u662f\u4e00\u4e2atarget\u4e3a\u7a7a\u7684Message\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><strong style=\"color: #916dd5;\">\u300c\u5de5\u4f5c\u539f\u7406\u300d<\/strong>\uff1aHandler\u7684\u6d88\u606f\u5904\u7406\u662f\u5728Looper.loop()\u65b9\u6cd5\u4ece\u6d88\u606f\u961f\u5217\u4e2d\u83b7\u53d6\u6d88\u606f\u5e76\u4ea4\u7ed9Handler\u5904\u7406\uff0c\u5176\u4e2d\u662f\u901a\u8fc7MessageQueue\u662f\u901a\u8fc7next\u65b9\u6cd5\u6765\u83b7\u53d6\u6d88\u606f\u7684\u3002<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #ddd; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #272822; border-radius: 5px;\"><span style=\"line-height: 26px;\">Message\u00a0<span style=\"color: #a6e22e; font-weight: bold; line-height: 26px;\">next<\/span><span style=\"line-height: 26px;\">()<\/span>\u00a0<\/span>{\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">final<\/span>\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">long<\/span>\u00a0ptr\u00a0=\u00a0mPtr;\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(ptr\u00a0==\u00a0<span style=\"line-height: 26px;\">0<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">return<\/span>\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>;\n\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">int<\/span>\u00a0pendingIdleHandlerCount\u00a0=\u00a0-<span style=\"line-height: 26px;\">1<\/span>;\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0-1\u00a0only\u00a0during\u00a0first\u00a0iteration<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">int<\/span>\u00a0nextPollTimeoutMillis\u00a0=\u00a0<span style=\"line-height: 26px;\">0<\/span>;\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">for<\/span>\u00a0(;;)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(nextPollTimeoutMillis\u00a0!=\u00a0<span style=\"line-height: 26px;\">0<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Binder.flushPendingCommands();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0nativePollOnce(ptr,\u00a0nextPollTimeoutMillis);\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">synchronized<\/span>\u00a0(<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">this<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0Try\u00a0to\u00a0retrieve\u00a0the\u00a0next\u00a0message.\u00a0\u00a0Return\u00a0if\u00a0found.<\/span>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">final<\/span>\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">long<\/span>\u00a0now\u00a0=\u00a0SystemClock.uptimeMillis();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Message\u00a0prevMsg\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Message\u00a0msg\u00a0=\u00a0mMessages;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(msg\u00a0!=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>\u00a0&amp;&amp;\u00a0msg.target\u00a0==\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">do<\/span>\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0prevMsg\u00a0=\u00a0msg;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0msg.next;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">while<\/span>\u00a0(msg\u00a0!=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>\u00a0&amp;&amp;\u00a0!msg.isAsynchronous());\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(msg\u00a0!=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(now\u00a0&lt;\u00a0msg.when)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0Next\u00a0message\u00a0is\u00a0not\u00a0ready.\u00a0\u00a0Set\u00a0a\u00a0timeout\u00a0to\u00a0wake\u00a0up\u00a0when\u00a0it\u00a0is\u00a0ready.<\/span>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0nextPollTimeoutMillis\u00a0=\u00a0(<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">int<\/span>)\u00a0Math.min(msg.when\u00a0-\u00a0now,\u00a0Integer.MAX_VALUE);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">else<\/span>\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0Got\u00a0a\u00a0message.<\/span>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mBlocked\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">false<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(prevMsg\u00a0!=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0prevMsg.next\u00a0=\u00a0msg.next;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">else<\/span>\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mMessages\u00a0=\u00a0msg.next;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg.next\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(DEBUG)\u00a0Log.v(TAG,\u00a0<span style=\"color: #a6e22e; line-height: 26px;\">\"Returning\u00a0message:\u00a0\"<\/span>\u00a0+\u00a0msg);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg.markInUse();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">return<\/span>\u00a0msg;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">else<\/span>\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0No\u00a0more\u00a0messages.<\/span>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0nextPollTimeoutMillis\u00a0=\u00a0-<span style=\"line-height: 26px;\">1<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(mQuitting)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0dispose();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">return<\/span>\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(pendingIdleHandlerCount\u00a0&lt;\u00a0<span style=\"line-height: 26px;\">0<\/span>\u00a0&amp;&amp;\u00a0(mMessages\u00a0==\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>\u00a0||\u00a0now\u00a0&lt;\u00a0mMessages.when))\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pendingIdleHandlerCount\u00a0=\u00a0mIdleHandlers.size();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(pendingIdleHandlerCount\u00a0&lt;=\u00a0<span style=\"line-height: 26px;\">0<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0No\u00a0idle\u00a0handlers\u00a0to\u00a0run.\u00a0\u00a0Loop\u00a0and\u00a0wait\u00a0some\u00a0more.<\/span>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mBlocked\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">true<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">continue<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(mPendingIdleHandlers\u00a0==\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mPendingIdleHandlers\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">new<\/span>\u00a0IdleHandler[Math.max(pendingIdleHandlerCount,\u00a0<span style=\"line-height: 26px;\">4<\/span>)];\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mPendingIdleHandlers\u00a0=\u00a0mIdleHandlers.toArray(mPendingIdleHandlers);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">for<\/span>\u00a0(<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">int<\/span>\u00a0i\u00a0=\u00a0<span style=\"line-height: 26px;\">0<\/span>;\u00a0i\u00a0&lt;\u00a0pendingIdleHandlerCount;\u00a0i++)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">final<\/span>\u00a0IdleHandler\u00a0idler\u00a0=\u00a0mPendingIdleHandlers[i];\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mPendingIdleHandlers[i]\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>;\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0release\u00a0the\u00a0reference\u00a0to\u00a0the\u00a0handler<\/span>\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">boolean<\/span>\u00a0keep\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">false<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">try<\/span>\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0keep\u00a0=\u00a0idler.queueIdle();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">catch<\/span>\u00a0(Throwable\u00a0t)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.wtf(TAG,\u00a0<span style=\"color: #a6e22e; line-height: 26px;\">\"IdleHandler\u00a0threw\u00a0exception\"<\/span>,\u00a0t);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(!keep)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">synchronized<\/span>\u00a0(<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">this<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mIdleHandlers.remove(idler);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pendingIdleHandlerCount\u00a0=\u00a0<span style=\"line-height: 26px;\">0<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0nextPollTimeoutMillis\u00a0=\u00a0<span style=\"line-height: 26px;\">0<\/span>;\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">msg.target == null\u65f6\u8bf4\u660e\u6b64\u65f6\u7684msg\u662f\u5c4f\u969c\u6d88\u606f\uff0c\u6b64\u65f6\u4f1a\u8fdb\u5165\u5230\u5faa\u73af\uff0c\u904d\u5386\u79fb\u52a8msg\u7684\u4f4d\u7f6e\uff0c\u76f4\u5230\u79fb\u52a8\u5230\u7684msg\u662f\u5f02\u6b65message\u9000\u51fa\u5faa\u73af\uff0c\u4e5f\u5c31\u662f\u8bf4\u5faa\u73af\u7684\u4ee3\u7801\u4f1a\u8fc7\u6ee4\u6389\u6240\u6709\u7684\u540c\u6b65\u6d88\u606f\uff0c\u76f4\u5230\u53d6\u51fa\u5f02\u6b65\u6d88\u606f\u4e3a\u6b62\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u5f53\u8bbe\u7f6e\u4e86\u540c\u6b65\u5c4f\u969c\u4e4b\u540e\uff0cnext\u51fd\u6570\u5c06\u4f1a\u5ffd\u7565\u6240\u6709\u7684\u540c\u6b65\u6d88\u606f\uff0c\u8fd4\u56de\u5f02\u6b65\u6d88\u606f\u3002\u8bbe\u7f6e\u4e86\u540c\u6b65\u5c4f\u969c\u4e4b\u540e\uff0cHandler\u53ea\u4f1a\u5904\u7406\u5f02\u6b65\u6d88\u606f\u3002\u540c\u6b65\u5c4f\u969c\u4e3aHandler\u6d88\u606f\u673a\u5236\u589e\u52a0\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u4f18\u5148\u7ea7\u673a\u5236\uff0c\u5f02\u6b65\u6d88\u606f\u7684\u4f18\u5148\u7ea7\u8981\u9ad8\u4e8e\u540c\u6b65\u6d88\u606f\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><strong style=\"color: #916dd5;\">\u300c\u79fb\u9664\u5c4f\u969c\u300d<\/strong>\uff1a\u5c4f\u969c\u4e0d\u4f1a\u81ea\u52a8\u79fb\u9664\uff0c\u9700\u8981\u624b\u52a8\u8c03\u7528<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #916dd5; font-weight: bolder; background-image: none; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;\">MessageQueue.removeSyncBarrier(int token)<\/code>\u65b9\u6cd5\u79fb\u9664\u3002<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #916dd5; font-weight: bolder; background-image: none; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;\">token<\/code>\u662f<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #916dd5; font-weight: bolder; background-image: none; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;\">postSyncBarrier()<\/code>\u65b9\u6cd5\u8fd4\u56de\u7684\u552f\u4e00\u6807\u8bc6\u7b26\u3002<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #ddd; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #272822; border-radius: 5px;\"><span style=\"line-height: 26px;\"><span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">public<\/span>\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">void<\/span>\u00a0<span style=\"color: #a6e22e; font-weight: bold; line-height: 26px;\">removeSyncBarrier<\/span><span style=\"line-height: 26px;\">(<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">int<\/span>\u00a0token)<\/span>\u00a0<\/span>{\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0Remove\u00a0a\u00a0sync\u00a0barrier\u00a0token\u00a0from\u00a0the\u00a0queue.<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0If\u00a0the\u00a0queue\u00a0is\u00a0no\u00a0longer\u00a0stalled\u00a0by\u00a0a\u00a0barrier\u00a0then\u00a0wake\u00a0it.<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">synchronized<\/span>\u00a0(<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">this<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Message\u00a0prev\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Message\u00a0p\u00a0=\u00a0mMessages;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0\u5faa\u73af\u904d\u5386\uff0c\u76f4\u5230\u9047\u5230\u5c4f\u969c\u6d88\u606f\u65f6\u63a8\u9000\u51fa\u5faa\u73af<\/span>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">while<\/span>\u00a0(p\u00a0!=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>\u00a0&amp;&amp;\u00a0(p.target\u00a0!=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>\u00a0||\u00a0p.arg1\u00a0!=\u00a0token))\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0prev\u00a0=\u00a0p;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0p\u00a0=\u00a0p.next;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(p\u00a0==\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">throw<\/span>\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">new<\/span>\u00a0IllegalStateException(<span style=\"color: #a6e22e; line-height: 26px;\">\"The\u00a0specified\u00a0message\u00a0queue\u00a0synchronization\u00a0\"<\/span>\u00a0+\u00a0<span style=\"color: #a6e22e; line-height: 26px;\">\"\u00a0barrier\u00a0token\u00a0has\u00a0not\u00a0been\u00a0posted\u00a0or\u00a0has\u00a0already\u00a0been\u00a0removed.\"<\/span>);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">final<\/span>\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">boolean<\/span>\u00a0needWake;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(prev\u00a0!=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0\u5220\u9664\u5c4f\u969c\u6d88\u606fp<\/span>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0prev.next\u00a0=\u00a0p.next;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0needWake\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">false<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">else<\/span>\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mMessages\u00a0=\u00a0p.next;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0needWake\u00a0=\u00a0mMessages\u00a0==\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>\u00a0||\u00a0mMessages.target\u00a0!=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0p.recycleUnchecked();\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0If\u00a0the\u00a0loop\u00a0is\u00a0quitting\u00a0then\u00a0it\u00a0is\u00a0already\u00a0awake.<\/span>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #75715e; line-height: 26px;\">\/\/\u00a0We\u00a0can\u00a0assume\u00a0mPtr\u00a0!=\u00a00\u00a0when\u00a0mQuitting\u00a0is\u00a0false.<\/span>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(needWake\u00a0&amp;&amp;\u00a0!mQuitting)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0nativeWake(mPtr);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u5220\u9664\u5c4f\u969c\u6d88\u606f\u7684\u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u4e0d\u65ad\u904d\u5386\u6d88\u606f\u961f\u5217\uff0c\u76f4\u5230\u627e\u5230\u5c4f\u969c\u6d88\u606f\uff0c\u9000\u51fa\u5faa\u73af\u7684\u6761\u4ef6\u6709\u4e24\u4e2ap.target == null(\u8bf4\u660e\u662f\u5c4f\u969c\u6d88\u606f)\u548cp.arg1 == token(\u8bf4\u660ep\u662f\u5c4f\u969c\u6d88\u606f\uff0c\u5728\u5c4f\u969c\u6d88\u606f\u5165\u961f\u7684\u65f6\u5019\uff0c\u8bbe\u7f6e\u8fc7msg.arg1 = token)\u3002\u627e\u5230\u5c4f\u969c\u6d88\u606f\u540e\uff0c\u628a\u5b83\u4ece\u6d88\u606f\u961f\u5217\u4e2d\u5220\u9664\u5e76\u56de\u6536\u3002<\/p>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; text-align: center;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"border-bottom: 2px solid #d89cf6;\">\u5f02\u6b65\u6d88\u606f<\/span><\/h3>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u901a\u5e38\u6211\u4eec\u4f7f\u7528Handler\u60f3\u6d88\u606f\u961f\u5217\u4e2d\u6dfb\u52a0\u7684Message\u90fd\u662f\u540c\u6b65\u7684\uff0c\u5982\u679c\u6211\u4eec\u60f3\u8981\u6dfb\u52a0\u4e00\u4e2a\u5f02\u6b65\u7684Message\uff0c\u6709\u4ee5\u4e0b\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n<ol class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px; font-size: 15px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\">Handler\u7684\u6784\u9020\u65b9\u6cd5\u6709\u4e2aasync\u53c2\u6570\uff0c\u9ed8\u8ba4\u7684\u6784\u9020\u65b9\u6cd5\u6b64\u53c2\u6570\u662ffalse\uff0c\u53ea\u8981\u5728\u6784\u9020handler\u5bf9\u8c61\u7684\u65f6\u5019\uff0c\u628a\u8be5\u53c2\u6570\u8bbe\u7f6e\u4e3atrue\u3002<\/section>\n<\/li>\n<\/ol>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #ddd; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #272822; border-radius: 5px;\"><span style=\"line-height: 26px;\"><span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">public<\/span>\u00a0<span style=\"color: #a6e22e; font-weight: bold; line-height: 26px;\">Handler<\/span><span style=\"line-height: 26px;\">(@Nullable\u00a0Callback\u00a0callback,\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">boolean<\/span>\u00a0async)<\/span>\u00a0<\/span>{\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(FIND_POTENTIAL_LEAKS)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">final<\/span>\u00a0Class\u00a0extends\u00a0Handler&gt;\u00a0klass\u00a0=\u00a0getClass();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0((klass.isAnonymousClass()\u00a0||\u00a0klass.isMemberClass()\u00a0||\u00a0klass.isLocalClass())\u00a0&amp;&amp;\u00a0(klass.getModifiers()\u00a0&amp;\u00a0Modifier.STATIC)\u00a0==\u00a0<span style=\"line-height: 26px;\">0<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.w(TAG,\u00a0<span style=\"color: #a6e22e; line-height: 26px;\">\"The\u00a0following\u00a0Handler\u00a0class\u00a0should\u00a0be\u00a0static\u00a0or\u00a0leaks\u00a0might\u00a0occur:\u00a0\"<\/span>\u00a0+\u00a0klass.getCanonicalName());\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0mLooper\u00a0=\u00a0Looper.myLooper();\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(mLooper\u00a0==\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">null<\/span>)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">throw<\/span>\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">new<\/span>\u00a0RuntimeException(\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #a6e22e; line-height: 26px;\">\"Can't\u00a0create\u00a0handler\u00a0inside\u00a0thread\u00a0\"<\/span>\u00a0+\u00a0Thread.currentThread()\u00a0+\u00a0<span style=\"color: #a6e22e; line-height: 26px;\">\"\u00a0that\u00a0has\u00a0not\u00a0called\u00a0Looper.prepare()\"<\/span>);\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0mQueue\u00a0=\u00a0mLooper.mQueue;\n\u00a0\u00a0\u00a0\u00a0mCallback\u00a0=\u00a0callback;\n\u00a0\u00a0\u00a0\u00a0mAsynchronous\u00a0=\u00a0async;\n\u00a0\u00a0\u00a0\u00a0mIsShared\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">false<\/span>;\n}\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; font-size: 14px; word-spacing: 2px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">async\u8bbe\u7f6e\u4e3atrue\u540e\uff0c\u5bf9\u5168\u5c40\u7684mAsynchronous\u8bbe\u7f6e\u4e3atrue\u3002\u7136\u540e\u5728enqueueMessage()\u8c03\u7528msg.setAsynchronous(true)\u5c06message\u8bbe\u7f6e\u4e3a\u5f02\u6b65\u7684\u3002<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #ddd; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #272822; border-radius: 5px;\"><span style=\"line-height: 26px;\"><span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">private<\/span>\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">boolean<\/span>\u00a0<span style=\"color: #a6e22e; font-weight: bold; line-height: 26px;\">enqueueMessage<\/span><span style=\"line-height: 26px;\">(@NonNull\u00a0MessageQueue\u00a0queue,\u00a0@NonNull\u00a0Message\u00a0msg,\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">long<\/span>\u00a0uptimeMillis)<\/span>\u00a0<\/span>{\n\u00a0\u00a0\u00a0\u00a0msg.target\u00a0=\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">this<\/span>;\n\u00a0\u00a0\u00a0\u00a0msg.workSourceUid\u00a0=\u00a0ThreadLocalWorkSource.getUid();\n\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">if<\/span>\u00a0(mAsynchronous)\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg.setAsynchronous(<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">true<\/span>);\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #f92672; font-weight: bold; line-height: 26px;\">return<\/span>\u00a0queue.enqueueMessage(msg,\u00a0uptimeMillis);\n}\n<\/code><\/pre>\n<ol class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px; font-size: 15px;\" start=\"2\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\">\u5728\u521b\u5efaMessage\u5bf9\u8c61\u65f6\u8c03\u7528Message\u7684setAsynchronous()\u65b9\u6cd5\u3002\u5728\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u5f02\u6b65\u6d88\u606f\u548c\u540c\u6b65\u6d88\u606f\u6ca1\u6709\u4ec0\u4e48\u533a\u522b\uff0c\u4f46\u5f00\u542f\u4e86\u540c\u6b65\u5c4f\u969c\u4ee5\u540e\u5c31\u6709\u533a\u522b\u4e86\u3002<\/section>\n<\/li>\n<\/ol>\n<ul class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px; font-size: 15px; list-style-type: circle;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\">\u5f53Looper\u4eceMessageQueue\u4e2d\u53d6\u51fa\u6d88\u606f\u8fdb\u884c\u5904\u7406\u65f6\uff0c\u5982\u679c\u9047\u5230\u5c4f\u969c\u6d88\u606f\uff0c\u4f1a\u8df3\u8fc7\u6240\u6709\u540e\u7eed\u7684\u666e\u901a\u6d88\u606f\uff0c\u76f4\u5230\u627e\u5230\u5f02\u6b65\u6d88\u606f\u6216\u5c4f\u969c\u88ab\u79fb\u9664\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\">\u5f02\u6b65\u6d88\u606f\u4e0d\u53d7\u540c\u6b65\u5c4f\u969c\u7684\u5f71\u54cd\uff0c\u53ef\u4ee5\u76f4\u63a5\u88ab\u5904\u7406\u3002<\/section>\n<\/li>\n<\/ul>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; text-align: center;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"border-bottom: 2px solid #d89cf6;\">\u5e94\u7528\u573a\u666f<\/span><\/h3>\n<ol class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px; font-size: 15px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\"><strong style=\"color: #916dd5;\">\u300c\u786e\u4fdd\u7acb\u5373\u4efb\u52a1\u4f18\u5148\u5904\u7406\u300d<\/strong>\uff1a\u5728\u9700\u8981\u4f18\u5148\u6267\u884c\u67d0\u4e9b\u7d27\u6025\u4efb\u52a1\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u540c\u6b65\u5c4f\u969c\u6682\u65f6\u963b\u6b62\u5176\u4ed6\u6d88\u606f\u7684\u5904\u7406\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\"><strong style=\"color: #916dd5;\">\u300c\u907f\u514d\u6b7b\u9501\u548c\u8d44\u6e90\u7ade\u4e89\u300d<\/strong>\uff1a\u5728\u590d\u6742\u7684\u6d88\u606f\u4ea4\u4e92\u573a\u666f\u4e2d\uff0c\u4f7f\u7528\u540c\u6b65\u5c4f\u969c\u53ef\u4ee5\u9632\u6b62\u56e0\u6d88\u606f\u5904\u7406\u987a\u5e8f\u4e0d\u5f53\u5f15\u53d1\u7684\u6b7b\u9501\u6216\u8d44\u6e90\u7ade\u4e89\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\"><strong style=\"color: #916dd5;\">\u300cUI\u7ed8\u5236\u4f18\u5316\u300d<\/strong>\uff1a\u5728Android\u5e94\u7528\u6846\u67b6\u4e2d\uff0c\u4e3a\u4e86\u66f4\u5feb\u5730\u54cd\u5e94UI\u5237\u65b0\u4e8b\u4ef6\uff0cViewRootImpl\u5728\u7ed8\u5236\u6d41\u7a0b\u4e2d\u4f7f\u7528\u4e86\u540c\u6b65\u5c4f\u969c\u673a\u5236\uff0c\u786e\u4fdd\u5f02\u6b65\u7ed8\u5236\u4efb\u52a1\u53ef\u4ee5\u4f18\u5148\u6267\u884c\u3002<\/section>\n<\/li>\n<\/ol>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; text-align: center;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"border-bottom: 2px solid #d89cf6;\">\u6ce8\u610f\u4e8b\u9879<\/span><\/h3>\n<ol class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px; font-size: 15px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\"><strong style=\"color: #916dd5;\">\u300c\u8c28\u614e\u4f7f\u7528\u300d<\/strong>\uff1a\u4e0d\u6070\u5f53\u7684\u4f7f\u7528\u540c\u6b65\u5c4f\u969c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6d88\u606f\u5904\u7406\u7684\u5ef6\u8fdf\u6216\u963b\u585e\uff0c\u5f71\u54cd\u5e94\u7528\u6027\u80fd\u548c\u54cd\u5e94\u80fd\u529b\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 14px;\"><strong style=\"color: #916dd5;\">\u300c\u624b\u52a8\u79fb\u9664\u300d<\/strong>\uff1a\u4f7f\u7528\u5b8c\u540c\u6b65\u5c4f\u969c\u540e\uff0c\u5fc5\u987b\u624b\u52a8\u79fb\u9664\uff0c\u5426\u5219\u4f1a\u9020\u6210\u540c\u6b65\u6d88\u606f\u65e0\u6cd5\u5904\u7406\u3002<\/section>\n<\/li>\n<\/ol>\n<\/section>\n<p style=\"display: none;\">\n","protected":false},"excerpt":{"rendered":"<p>Handler\u540c\u6b65\u5c4f\u969c\u673a\u5236\u662fAndroid\u5f00\u53d1\u4e2d\u4e00\u4e2a\u8f83\u4e3a\u9ad8\u7ea7\u4e14\u590d\u6742\u7684\u7279\u6027\uff0c\u4e3b\u8981\u7528\u4e8e\u63a7\u5236\u6d88\u606f\u961f\u5217MessageQ&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":71,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-83","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/posts\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":0,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/media\/71"}],"wp:attachment":[{"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}