{"id":244,"date":"2026-09-06T00:43:45","date_gmt":"2026-09-05T16:43:45","guid":{"rendered":"https:\/\/www.ziliaochi.cn\/index.php\/2026\/09\/06\/interview-android-core\/"},"modified":"2026-09-06T00:43:45","modified_gmt":"2026-09-05T16:43:45","slug":"interview-android-core","status":"publish","type":"post","link":"https:\/\/www.ziliaochi.cn\/index.php\/2026\/09\/06\/interview-android-core\/","title":{"rendered":"Android \u9762\u8bd5\u9ad8\u9891 25 \u95ee\uff1aHandler\u3001Binder\u3001\u56db\u5927\u7ec4\u4ef6\u4e0e Compose"},"content":{"rendered":"<div style=\"font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",\"PingFang SC\",\"Hiragino Sans GB\",\"Microsoft YaHei\",sans-serif;font-size:16.5px;line-height:1.9;color:#35435c;letter-spacing:.2px\">\n<div style=\"background:linear-gradient(135deg,#f5f9ff,#eef5ff);border:1px solid #dce8f8;border-left:4px solid #6b5ce7;border-radius:12px;padding:16px 20px;margin:0 0 24px;font-size:14.5px;color:#3d5570;line-height:2\"><span style=\"display:inline-block;background:#6b5ce7;color:#fff;font-size:12.5px;font-weight:700;padding:3px 10px;border-radius:6px;margin-right:12px;letter-spacing:1px;vertical-align:1px\">\u5173\u952e\u8bcd<\/span>Android \u9762\u8bd5\u3001Handler \u673a\u5236\u3001Binder\u3001Activity \u751f\u547d\u5468\u671f\u3001Jetpack Compose<\/div>\n<div style=\"background:#fafbfd;border:1px solid #e8edf5;border-radius:12px;padding:18px 22px;margin:0 0 30px\">\n<div style=\"font-size:13.5px;font-weight:700;color:#8a99ae;letter-spacing:2px;margin-bottom:12px\">\u76ee\u5f55<\/div>\n<ol style=\"margin:0;padding-left:20px\">\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-1\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e00\u3001Handler\uff1a\u9762\u8bd5\u7684\u7b2c\u4e00\u9053\u5206\u6c34\u5cad<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-2\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e8c\u3001Binder\uff1aAndroid \u7684 IPC \u5fc3\u810f<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-3\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e09\u3001\u56db\u5927\u7ec4\u4ef6\u4e0e\u751f\u547d\u5468\u671f<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-4\" style=\"color:#42546e;text-decoration:none;border:none\">\u56db\u3001View \u7ed8\u5236\u4e0e\u6027\u80fd<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-5\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e94\u3001Jetpack Compose\uff1a2026 \u5e74\u7684\u5fc5\u8003\u533a<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-6\" style=\"color:#42546e;text-decoration:none;border:none\">\u516d\u3001\u5c0f\u7ed3<\/a><\/li>\n<\/ol>\n<\/div>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\"><span style=\"font-size:17px;color:#1e2f47\">Android \u9762\u8bd5\u7684&#8221;\u539f\u7406\u9898&#8221;\u6709\u975e\u5e38\u7a33\u5b9a\u7684\u6838\u5fc3\u533a\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u56db\u5927\u7ec4\u4ef6\u3001Handler\u3001Binder\u3001View \u7ed8\u5236\u3001\u5185\u5b58\u6cc4\u6f0f\u3001Compose<\/strong>\u3002\u8fd9\u4e9b\u5185\u5bb9\u4e0d\u968f\u7248\u672c\u5267\u70c8\u53d8\u52a8\uff0c\u4f46\u8003\u5bdf\u6df1\u5ea6\u5dee\u5f02\u5f88\u5927\u2014\u2014\u540c\u6837\u95ee&#8221;Handler \u539f\u7406&#8221;\uff0c\u6709\u4eba\u8bf4\u5230 Looper \u5c31\u505c\u4e86\uff0c\u6709\u4eba\u80fd\u8bb2\u6e05<strong style=\"color:#0f1c2e;font-weight:600\">\u4e3a\u4ec0\u4e48\u4e3b\u7ebf\u7a0b Looper \u6b7b\u5faa\u73af\u4e0d\u4f1a ANR<\/strong>\u3002<\/p>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u672c\u6587\u6309\u9ad8\u9891\u8003\u70b9\u7ec4\u7ec7\uff0c\u6bcf\u9898\u7ed9\u51fa&#8221;\u6807\u51c6\u7b54\u6cd5 + \u8ffd\u95ee\u9677\u9631 + \u9762\u8bd5\u5b98\u60f3\u542c\u7684\u90a3\u53e5\u8bdd&#8221;\u3002\u7248\u672c\u80cc\u666f\uff1aAndroid 17 \u5df2 GA\uff0c\u4e24\u7aef target SDK \u7684\u5e74\u5ea6\u5347\u7ea7\u7a97\u53e3\u540c\u65f6\u751f\u6548\u3002<\/p>\n<figure style=\"margin:30px 0;text-align:center\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"900\" src=\"https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/interview-android-core-fig.png\" alt=\"Handler \u673a\u5236\u7684\u56db\u4e2a\u89d2\u8272\" class=\"wp-image-243\" style=\"max-width:100%;height:auto;border-radius:12px;border:1px solid #e6ecf4;box-shadow:0 8px 24px rgba(15,30,60,.07)\" srcset=\"https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/interview-android-core-fig.png 1200w, https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/interview-android-core-fig-300x225.png 300w, https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/interview-android-core-fig-1024x768.png 1024w, https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/interview-android-core-fig-768x576.png 768w, https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/interview-android-core-fig-800x600.png 800w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><figcaption style=\"margin-top:12px;font-size:13.5px;color:#7b8aa0;text-align:center;line-height:1.75\">Handler \u673a\u5236\uff1aMessage \u2192 MessageQueue \u2192 Looper \u2192 Handler<\/figcaption><\/figure>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #6b5ce7;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-1\">\u4e00\u3001Handler\uff1a\u9762\u8bd5\u7684\u7b2c\u4e00\u9053\u5206\u6c34\u5cad<\/h2>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q1\uff1aHandler \u673a\u5236\u6d89\u53ca\u54ea\u51e0\u4e2a\u7c7b\uff1f\u5404\u81ea\u505a\u4ec0\u4e48\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u56db\u4e2a\u89d2\u8272\u5fc5\u987b\u8bf4\u5168\uff1a<\/p>\n<ul style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">Message<\/code><\/strong>\uff1a\u6d88\u606f\u8f7d\u4f53\u3002<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">what<\/code>\/<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">arg1<\/code>\/<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">obj<\/code>\/<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">target<\/code>\uff0c\u4ee5\u53ca\u7528\u4e8e\u590d\u7528\u7684<strong style=\"color:#0f1c2e;font-weight:600\">\u6d88\u606f\u6c60<\/strong>\uff08<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">obtain()<\/code> \u4ece\u94fe\u8868\u4e2d\u53d6\uff0c\u907f\u514d\u9891\u7e41\u521b\u5efa\u5bf9\u8c61\uff09\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">MessageQueue<\/code><\/strong>\uff1a\u6309 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">when<\/code>\uff08\u6267\u884c\u65f6\u95f4\uff09\u6392\u5e8f\u7684<strong style=\"color:#0f1c2e;font-weight:600\">\u5355\u5411\u94fe\u8868<\/strong>\u3002\u6ce8\u610f\u662f\u94fe\u8868\u4e0d\u662f\u961f\u5217\uff0c\u63d2\u5165\u662f\u6309\u65f6\u95f4\u505a\u6709\u5e8f\u63d2\u5165\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">Looper<\/code><\/strong>\uff1a\u6301\u6709 MessageQueue\uff0c<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">loop()<\/code> \u65b9\u6cd5\u91cc\u6b7b\u5faa\u73af\u53d6\u6d88\u606f\u5e76\u5206\u53d1\u3002<strong style=\"color:#0f1c2e;font-weight:600\">\u6bcf\u4e2a\u7ebf\u7a0b\u6700\u591a\u4e00\u4e2a Looper<\/strong>\uff0c\u7528 ThreadLocal \u4fdd\u8bc1\u7ebf\u7a0b\u9694\u79bb\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">Handler<\/code><\/strong>\uff1a\u53d1\u9001\u6d88\u606f\u5230 MessageQueue\uff0c\u5e76\u5728 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">dispatchMessage()<\/code> \u91cc\u5904\u7406\u3002<\/li>\n<\/ul>\n<pre style=\"background:#0f1a2b;color:#dbe6f5;border-radius:12px;padding:18px 20px;overflow-x:auto;font-size:13.6px;line-height:1.78;margin:22px 0;border:1px solid #1e2c42;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace\"><code style=\"background:none;border:none;color:inherit;padding:0;font-size:inherit;font-family:inherit\">\/\/ loop() \u7684\u6838\u5fc3\u903b\u8f91\uff08\u7b80\u5316\uff09\npublic static void loop() {\n    final Looper me = myLooper();\n    final MessageQueue queue = me.mQueue;\n    for (;;) {\n        Message msg = queue.next();   \/\/ \u6ca1\u6d88\u606f\u65f6\u5728\u8fd9\u91cc\u963b\u585e\uff08nativePollOnce\uff09\n        if (msg == null) return;\n        msg.target.dispatchMessage(msg);\n        msg.recycleUnchecked();        \/\/ \u56de\u6536\u8fdb\u6d88\u606f\u6c60\n    }\n}<\/code><\/pre>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q2\uff1a\u4e3b\u7ebf\u7a0b\u7684 Looper \u6b7b\u5faa\u73af\u4e3a\u4ec0\u4e48\u4e0d\u4f1a ANR\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u8fd9\u662f Handler \u6700\u7ecf\u5178\u7684\u8ffd\u95ee\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u7b54\u4e0d\u4e0a\u6765\u57fa\u672c\u5224\u5b9a\u4e3a&#8221;\u80cc\u8fc7\u4f46\u6ca1\u7406\u89e3&#8221;<\/strong>\u3002<\/p>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u5173\u952e\u70b9\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">ANR \u4e0d\u662f&#8221;\u5361\u4f4f&#8221;\uff0c\u800c\u662f&#8221;\u8be5\u5904\u7406\u7684\u4e8b\u4ef6\u6ca1\u5728\u89c4\u5b9a\u65f6\u95f4\u5185\u5904\u7406\u5b8c&#8221;<\/strong>\u3002\u4e3b\u7ebf\u7a0b Looper \u7684\u6b7b\u5faa\u73af\uff0c\u5728<strong style=\"color:#0f1c2e;font-weight:600\">\u6ca1\u6709\u6d88\u606f\u65f6\u662f\u901a\u8fc7 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">nativePollOnce<\/code> \u8fdb\u5165 epoll \u7b49\u5f85\u7761\u7720\u7684\uff0c\u4e0d\u6d88\u8017 CPU<\/strong>\uff1b\u6709\u6d88\u606f\u5230\u6765\u65f6\u88ab\u5524\u9192\u7ee7\u7eed\u6267\u884c\u3002\u6240\u8c13 ANR\uff0c\u662f\u67d0\u6761\u6d88\u606f\uff08\u5982 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">INPUT<\/code> \u4e8b\u4ef6\u3001<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">BroadcastReceiver.onReceive<\/code>\uff09\u6267\u884c\u8d85\u8fc7\u9608\u503c\uff08\u8f93\u5165\u4e8b\u4ef6 5s\u3001\u524d\u53f0\u5e7f\u64ad 10s\u3001Service 20s\uff09\uff0c\u800c\u975e\u5faa\u73af\u672c\u8eab\u3002<\/p>\n<blockquote style=\"margin:24px 0;padding:16px 22px;background:#f7fafd;border-left:4px solid #6b5ce7;border-radius:0 10px 10px 0;color:#4a5b73;font-size:15.6px;line-height:1.88\">\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4e00\u53e5\u8bdd\u7248\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u6b7b\u5faa\u73af\u5728&#8221;\u7b49\u6d88\u606f&#8221;\uff0c\u4e0d\u5728&#8221;\u5fd9\u7b49&#8221;\uff1b\u5524\u9192\u9760 Linux \u7684 epoll \u673a\u5236\uff1bANR \u662f\u5355\u6761\u6d88\u606f\u6267\u884c\u8d85\u65f6\uff0c\u4e0d\u662f\u5faa\u73af\u5bfc\u81f4\u7684\u3002<\/strong><\/p>\n<\/blockquote>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q3\uff1a<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">Handler.postDelayed<\/code> \u662f\u7cbe\u786e\u5ef6\u65f6\u5417\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u4e0d\u662f\u3002<\/strong>\u5b83\u53ea\u662f\u5728 MessageQueue \u91cc\u6309 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">when = \u5f53\u524d\u65f6\u95f4 + delay<\/code> \u63d2\u5165\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u5230\u70b9\u540e\u80fd\u5426\u7acb\u5373\u6267\u884c\u53d6\u51b3\u4e8e\u524d\u9762\u6709\u6ca1\u6709\u79ef\u538b\u7684\u6d88\u606f<\/strong>\u3002\u5982\u679c\u4e3b\u7ebf\u7a0b\u6b63\u88ab\u4e00\u4e2a\u8017\u65f6\u64cd\u4f5c\u5360\u7740\uff0c\u5ef6\u65f6\u4f1a\u88ab\u987a\u5ef6\u3002\u6b64\u5916\u7cfb\u7edf\u8fd8\u53ef\u80fd\u56e0\u4e3a<strong style=\"color:#0f1c2e;font-weight:600\">\u5bf9\u9f50\u5524\u9192\uff08Alarm alignment\uff09\u3001Doze \u6a21\u5f0f<\/strong>\u505a\u6279\u91cf\u5ef6\u8fdf\u3002<\/p>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u9700\u8981\u7cbe\u786e\u8ba1\u65f6\u7684\u573a\u666f\uff08\u5982\u5012\u8ba1\u65f6\uff09\u5e94\u5f53<strong style=\"color:#0f1c2e;font-weight:600\">\u7528\u7cfb\u7edf\u65f6\u95f4\u6233\u5b9e\u65f6\u8ba1\u7b97\u5269\u4f59\u503c<\/strong>\uff0c\u800c\u4e0d\u662f\u7d2f\u52a0 postDelayed \u7684 delay\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q4\uff1aHandler \u5f15\u8d77\u5185\u5b58\u6cc4\u6f0f\u7684\u539f\u56e0\u4e0e\u89e3\u6cd5\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u6cc4\u6f0f\u94fe\uff1a<\/strong>\u5ef6\u65f6\u6d88\u606f <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">msg.target<\/code> \u6301\u6709 Handler \u2192 Handler \u662f\u975e\u9759\u6001\u5185\u90e8\u7c7b\uff0c\u9690\u5f0f\u6301\u6709 Activity \u2192 Activity \u5df2 finish \u4f46\u6d88\u606f\u8fd8\u5728\u961f\u5217\u91cc \u2192 Activity \u65e0\u6cd5\u56de\u6536\u3002<\/p>\n<pre style=\"background:#0f1a2b;color:#dbe6f5;border-radius:12px;padding:18px 20px;overflow-x:auto;font-size:13.6px;line-height:1.78;margin:22px 0;border:1px solid #1e2c42;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace\"><code style=\"background:none;border:none;color:inherit;padding:0;font-size:inherit;font-family:inherit\">\/\/ \u53cd\u4f8b\uff1a\u975e\u9759\u6001\u5185\u90e8\u7c7b + \u5ef6\u65f6\u6d88\u606f\nclass MainActivity : AppCompatActivity() {\n    private val handler = Handler(Looper.getMainLooper())   \/\/ \u9690\u5f0f\u6301\u6709 Activity\n    override fun onCreate(...) {\n        handler.postDelayed({ updateUI() }, 60_000)\n    }\n}\n\n\/\/ \u6b63\u4f8b1\uff1a\u9759\u6001\u5185\u90e8\u7c7b + \u5f31\u5f15\u7528\nclass SafeHandler(activity: MainActivity) : Handler(Looper.getMainLooper()) {\n    private val ref = WeakReference(activity)\n    override fun handleMessage(msg: Message) {\n        ref.get()?.updateUI()\n    }\n}\n\n\/\/ \u6b63\u4f8b2\uff1a\u751f\u547d\u5468\u671f\u611f\u77e5\uff0c\u9500\u6bc1\u65f6\u6e05\u7a7a\u6d88\u606f\noverride fun onDestroy() {\n    super.onDestroy()\n    handler.removeCallbacksAndMessages(null)   \/\/ \u5173\u952e\uff1a\u79fb\u9664\u6240\u6709\u56de\u8c03\n}<\/code><\/pre>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #6b5ce7;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-2\">\u4e8c\u3001Binder\uff1aAndroid \u7684 IPC \u5fc3\u810f<\/h2>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q5\uff1a\u4e3a\u4ec0\u4e48 Android \u7528 Binder \u800c\u4e0d\u7528 Socket \u6216\u5171\u4eab\u5185\u5b58\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4ece\u4e09\u4e2a\u7ef4\u5ea6\u5bf9\u6bd4\uff1a<\/p>\n<table style=\"width:100%;border-collapse:collapse;margin:24px 0;font-size:15px;border:1px solid #e3eaf3;border-radius:10px;overflow:hidden\">\n<thead>\n<tr>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">\u7ef4\u5ea6<\/th>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">Binder<\/th>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">Socket<\/th>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">\u5171\u4eab\u5185\u5b58<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u62f7\u8d1d\u6b21\u6570<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\"><strong style=\"color:#0f1c2e;font-weight:600\">1 \u6b21<\/strong><\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">2 \u6b21<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">0 \u6b21<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u5b89\u5168\u6027<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\"><strong style=\"color:#0f1c2e;font-weight:600\">\u5185\u6838\u6821\u9a8c UID\/PID<\/strong><\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u4f9d\u8d56\u4e0a\u5c42\u534f\u8bae<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u65e0\u8bbf\u95ee\u63a7\u5236<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u4f7f\u7528\u6a21\u578b<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">C\/S \u67b6\u6784\uff0c\u9762\u5411\u5bf9\u8c61\u8c03\u7528<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u5b57\u8282\u6d41<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u9700\u81ea\u884c\u5904\u7406\u540c\u6b65<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u8981\u70b9\u5c55\u5f00\uff1a<\/p>\n<ul style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u6027\u80fd<\/strong>\uff1aBinder \u901a\u8fc7 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">mmap<\/code> \u628a\u5185\u6838\u7f13\u51b2\u533a\u540c\u65f6\u6620\u5c04\u5230\u5185\u6838\u7a7a\u95f4\u548c\u670d\u52a1\u7aef\u7528\u6237\u7a7a\u95f4\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u6570\u636e\u53ea\u9700\u4ece\u53d1\u9001\u65b9\u7528\u6237\u7a7a\u95f4\u62f7\u8d1d\u4e00\u6b21\u5230\u5185\u6838<\/strong>\uff0c\u63a5\u6536\u65b9\u76f4\u63a5\u8bfb\u6620\u5c04\u533a\u3002\u5171\u4eab\u5185\u5b58\u867d\u7136\u96f6\u62f7\u8d1d\uff0c\u4f46\u9700\u8981\u81ea\u5df1\u89e3\u51b3\u5e76\u53d1\u540c\u6b65\uff0c\u4e14\u6ca1\u6709\u8bbf\u95ee\u63a7\u5236\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u5b89\u5168<\/strong>\uff1aBinder \u9a71\u52a8\u5728\u5185\u6838\u6001\u8bb0\u5f55\u8c03\u7528\u65b9\u7684 UID\/PID\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u670d\u52a1\u7aef\u53ef\u4ee5\u636e\u6b64\u505a\u6743\u9650\u6821\u9a8c<\/strong>\u2014\u2014\u8fd9\u662f Android \u6743\u9650\u4f53\u7cfb\u7684\u57fa\u77f3\u3002Socket \u548c\u5171\u4eab\u5185\u5b58\u62ff\u4e0d\u5230\u53ef\u9760\u7684\u8eab\u4efd\u6807\u8bc6\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u6613\u7528\u6027<\/strong>\uff1aBinder \u662f\u9762\u5411\u5bf9\u8c61\u7684\uff08AIDL \u751f\u6210\u7684\u4ee3\u7406\u6a21\u5f0f\uff09\uff0c\u8c03\u7528\u8fdc\u7a0b\u65b9\u6cd5\u50cf\u8c03\u7528\u672c\u5730\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q6\uff1aBinder \u901a\u4fe1\u7684\u5b8c\u6574\u6d41\u7a0b\uff1f<\/h3>\n<ol style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u6ce8\u518c<\/strong>\uff1aServer \u5411 <strong style=\"color:#0f1c2e;font-weight:600\">ServiceManager<\/strong>\uff08\u672c\u8eab\u4e5f\u662f\u4e00\u4e2a Binder \u670d\u52a1\uff0chandle = 0\uff09\u6ce8\u518c\u670d\u52a1\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u83b7\u53d6<\/strong>\uff1aClient \u5411 ServiceManager \u67e5\u8be2\uff0c\u62ff\u5230\u670d\u52a1\u7684\u4ee3\u7406\u5bf9\u8c61\uff08<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">BinderProxy<\/code>\uff09\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u8c03\u7528<\/strong>\uff1aClient \u8c03\u7528\u4ee3\u7406\u65b9\u6cd5\uff0c\u6570\u636e\u6253\u5305\u6210 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">Parcel<\/code>\uff0c\u901a\u8fc7 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">transact()<\/code> \u53d1\u7ed9 Binder \u9a71\u52a8\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u9a71\u52a8\u8f6c\u53d1<\/strong>\uff1a\u9a71\u52a8\u6839\u636e handle \u627e\u5230\u76ee\u6807\u8fdb\u7a0b\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u62f7\u8d1d\u4e00\u6b21\u6570\u636e<\/strong>\uff0c\u628a\u8bf7\u6c42\u52a0\u5165\u670d\u52a1\u7aef\u7684 todo \u961f\u5217\uff0c\u5524\u9192\u670d\u52a1\u7aef Binder \u7ebf\u7a0b\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u6267\u884c\u4e0e\u8fd4\u56de<\/strong>\uff1a\u670d\u52a1\u7aef\u5728 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">onTransact()<\/code> \u4e2d\u89e3\u5305\u6267\u884c\uff0c\u7ed3\u679c\u6cbf\u539f\u8def\u8fd4\u56de\u3002<\/li>\n<\/ol>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u540c\u6b65\u8c03\u7528\u65f6\u5ba2\u6237\u7aef\u7ebf\u7a0b\u4f1a\u963b\u585e<\/strong>\uff0c\u6240\u4ee5\u8981\u907f\u514d\u5728<strong style=\"color:#0f1c2e;font-weight:600\">\u4e3b\u7ebf\u7a0b<\/strong>\u8c03\u7528\u8017\u65f6\u8fdc\u7a0b\u65b9\u6cd5\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q7\uff1aAIDL \u7684 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">oneway<\/code>\u3001<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">in<\/code>\/<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">out<\/code>\/<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">inout<\/code> \u662f\u4ec0\u4e48\uff1f<\/h3>\n<ul style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">oneway<\/code><\/strong>\uff1a\u5f02\u6b65\u8c03\u7528\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u7acb\u5373\u8fd4\u56de\u4e0d\u963b\u585e<\/strong>\uff0c\u4e5f\u4e0d\u63a5\u6536\u8fd4\u56de\u503c\u3002\u9002\u7528\u4e8e&#8221;\u901a\u77e5&#8221;\u578b\u63a5\u53e3\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">in<\/code><\/strong>\uff1a\u6570\u636e\u53ea\u4ece\u5ba2\u6237\u7aef\u6d41\u5411\u670d\u52a1\u7aef\uff08\u9ed8\u8ba4\uff09\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">out<\/code><\/strong>\uff1a\u6570\u636e\u53ea\u4ece\u670d\u52a1\u7aef\u5199\u56de\u5ba2\u6237\u7aef\uff0c\u5ba2\u6237\u7aef\u4f20\u5165\u7684\u5bf9\u8c61\u5185\u5bb9\u4e0d\u4f1a\u88ab\u8bfb\u53d6\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">inout<\/code><\/strong>\uff1a\u53cc\u5411\u3002\u4ee3\u4ef7\u662f\u4e24\u6b21\u5e8f\u5217\u5316\u5f00\u9500\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u5b9e\u8df5\u4e2d\u5f88\u5c11\u7528<\/strong>\u3002<\/li>\n<\/ul>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #6b5ce7;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-3\">\u4e09\u3001\u56db\u5927\u7ec4\u4ef6\u4e0e\u751f\u547d\u5468\u671f<\/h2>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q8\uff1aActivity \u542f\u52a8\u6a21\u5f0f\u6709\u54ea\u51e0\u79cd\uff1f<\/h3>\n<ul style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">standard<\/code><\/strong>\uff1a\u9ed8\u8ba4\uff0c\u6bcf\u6b21\u90fd\u65b0\u5efa\u5b9e\u4f8b\uff0c\u538b\u5165\u542f\u52a8\u5b83\u7684\u90a3\u4e2a\u4efb\u52a1\u6808\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">singleTop<\/code><\/strong>\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u6808\u9876\u590d\u7528<\/strong>\u3002\u82e5\u76ee\u6807\u5df2\u5728\u6808\u9876\u5219\u590d\u7528\uff0c\u56de\u8c03 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">onNewIntent()<\/code>\u3002\u9002\u5408\u9632\u6b62\u91cd\u590d\u70b9\u51fb\u6253\u5f00\u540c\u4e00\u4e2a\u9875\u9762\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">singleTask<\/code><\/strong>\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u6808\u5185\u590d\u7528<\/strong>\u3002\u82e5\u6808\u4e2d\u5df2\u6709\u5b9e\u4f8b\uff0c\u5219<strong style=\"color:#0f1c2e;font-weight:600\">\u628a\u5b83\u4e0a\u9762\u7684\u6240\u6709 Activity \u5168\u90e8\u51fa\u6808<\/strong>\uff08clearTop\uff09\uff0c\u5e76\u56de\u8c03 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">onNewIntent()<\/code>\u3002\u9002\u5408\u4e3b\u9875\u3001\u767b\u5f55\u9875\u8fd9\u7c7b\u5168\u5c40\u552f\u4e00\u7684\u5165\u53e3\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">singleInstance<\/code><\/strong>\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u72ec\u5360\u4e00\u4e2a\u4efb\u52a1\u6808<\/strong>\uff0c\u7cfb\u7edf\u5185\u5168\u5c40\u552f\u4e00\u3002\u9002\u5408\u6765\u7535\u754c\u9762\u3001\u9501\u5c4f\u8fd9\u7c7b\u9700\u8981\u72ec\u7acb\u5b58\u5728\u7684\u9875\u9762\u3002<\/li>\n<\/ul>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u8ffd\u95ee&#8221;<strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">taskAffinity<\/code> \u6709\u4ec0\u4e48\u7528<\/strong>&#8220;\u2014\u2014\u5b83\u6307\u5b9a Activity \u5f52\u5c5e\u7684\u4efb\u52a1\u6808\u540d\uff0c\u4e0e <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">singleTask<\/code> \u6216 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">allowTaskReparenting<\/code> \u914d\u5408\u4f7f\u7528\u65f6\u624d\u751f\u6548\uff0c\u53ef\u4ee5\u5b9e\u73b0&#8221;\u628a\u67d0\u4e2a Activity \u632a\u5230\u53e6\u4e00\u4e2a\u4efb\u52a1\u6808&#8221;\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q9\uff1a\u6a2a\u7ad6\u5c4f\u5207\u6362\u65f6 Activity \u7684\u751f\u547d\u5468\u671f\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b<strong style=\"color:#0f1c2e;font-weight:600\">\u4f1a\u9500\u6bc1\u91cd\u5efa<\/strong>\uff1a<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">onPause \u2192 onStop \u2192 onDestroy \u2192 onCreate \u2192 onStart \u2192 onResume<\/code>\u3002<\/p>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u82e5\u914d\u7f6e <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">android:configChanges=\"orientation|screenSize\"<\/code>\uff0c\u5219<strong style=\"color:#0f1c2e;font-weight:600\">\u4e0d\u91cd\u5efa<\/strong>\uff0c\u53ea\u56de\u8c03 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">onConfigurationChanged()<\/code>\u3002<\/p>\n<blockquote style=\"margin:24px 0;padding:16px 22px;background:#f7fafd;border-left:4px solid #6b5ce7;border-radius:0 10px 10px 0;color:#4a5b73;font-size:15.6px;line-height:1.88\">\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u73b0\u4ee3\u7b54\u6cd5\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u4e0d\u8981\u9760 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">configChanges<\/code> \u9003\u907f\u91cd\u5efa\uff0c\u800c\u5e94\u8be5\u7528 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">ViewModel<\/code> \u6b63\u786e\u4fdd\u5b58\u72b6\u6001\u3002<\/strong><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">ViewModel<\/code> \u7684\u751f\u547d\u5468\u671f\u72ec\u7acb\u4e8e Activity \u7684\u914d\u7f6e\u53d8\u66f4\uff0c\u6570\u636e\u5728\u91cd\u5efa\u540e\u81ea\u52a8\u4fdd\u7559\u3002\u8fd9\u4e5f\u662f Google \u5b98\u65b9\u63a8\u8350\u7684\u67b6\u6784\u65b9\u5f0f\u2014\u2014<strong style=\"color:#0f1c2e;font-weight:600\">\u628a&#8221;\u914d\u7f6e\u53d8\u66f4&#8221;\u5f53\u6210\u4e00\u6b21\u6b63\u5e38\u7684\u751f\u547d\u5468\u671f\u4e8b\u4ef6\u6765\u5904\u7406\uff0c\u800c\u4e0d\u662f\u7ed5\u8fc7\u5b83<\/strong>\u3002<\/p>\n<\/blockquote>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q10\uff1aService \u7684\u4e24\u79cd\u542f\u52a8\u65b9\u5f0f\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/h3>\n<table style=\"width:100%;border-collapse:collapse;margin:24px 0;font-size:15px;border:1px solid #e3eaf3;border-radius:10px;overflow:hidden\">\n<thead>\n<tr>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\">\u7ef4\u5ea6<\/th>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">startService<\/code><\/th>\n<th style=\"background:#f2f6fb;color:#12233a;font-weight:700;padding:12px 14px;text-align:left;border-bottom:1px solid #e3eaf3;font-size:15px\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">bindService<\/code><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u751f\u547d\u5468\u671f<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u72ec\u7acb\uff0c\u9700\u663e\u5f0f <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">stopService<\/code>\/<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">stopSelf<\/code><\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u968f\u8c03\u7528\u65b9\uff0c\u5168\u90e8\u89e3\u7ed1\u5373\u9500\u6bc1<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u901a\u4fe1<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u5355\u5411\uff0c\u65e0\u76f4\u63a5\u56de\u8c03<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u53ef\u901a\u8fc7 Binder \u53cc\u5411\u901a\u4fe1<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u5178\u578b\u573a\u666f<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u4e0b\u8f7d\u3001\u64ad\u653e\uff08\u957f\u671f\u540e\u53f0\uff09<\/td>\n<td style=\"padding:12px 14px;border-bottom:1px solid #eff4fa;color:#3a4a63;line-height:1.75\">\u83b7\u53d6\u670d\u52a1\u5b9e\u4f8b\u3001\u8de8\u8fdb\u7a0b\u8c03\u7528<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u9ad8\u9891\u8ffd\u95ee\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u540e\u53f0\u9650\u5236<\/strong>\u3002Android 8.0 \u8d77\u7981\u6b62\u540e\u53f0\u5e94\u7528\u521b\u5efa\u540e\u53f0\u670d\u52a1\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u957f\u671f\u4efb\u52a1\u5fc5\u987b\u7528\u524d\u53f0\u670d\u52a1\uff08<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">startForegroundService<\/code> + \u5e38\u9a7b\u901a\u77e5\uff09<\/strong>\uff0c\u6216\u6539\u7528 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">WorkManager<\/code> \u5904\u7406\u53ef\u5ef6\u8fdf\u7684\u540e\u53f0\u5de5\u4f5c\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q11\uff1aBroadcastReceiver \u7684\u4e24\u79cd\u6ce8\u518c\u65b9\u5f0f\uff1f<\/h3>\n<ul style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u9759\u6001\u6ce8\u518c<\/strong>\uff08Manifest\uff09\uff1a\u5e94\u7528\u672a\u542f\u52a8\u4e5f\u80fd\u6536\u5230\uff0c\u4f46 Android 8.0 \u8d77<strong style=\"color:#0f1c2e;font-weight:600\">\u5927\u90e8\u5206\u9690\u5f0f\u5e7f\u64ad\u88ab\u7981\u6b62\u9759\u6001\u6ce8\u518c<\/strong>\uff08\u8c41\u514d\u5217\u8868\u5185\u7684\u9664\u5916\uff09\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u52a8\u6001\u6ce8\u518c<\/strong>\uff08<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">registerReceiver<\/code>\uff09\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u8ddf\u968f\u7ec4\u4ef6\u751f\u547d\u5468\u671f\uff0c\u5fc5\u987b\u5728 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">onDestroy<\/code>\/<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">onStop<\/code> \u4e2d\u53cd\u6ce8\u518c<\/strong>\uff0c\u5426\u5219\u5185\u5b58\u6cc4\u6f0f\u3002<\/li>\n<\/ul>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #6b5ce7;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-4\">\u56db\u3001View \u7ed8\u5236\u4e0e\u6027\u80fd<\/h2>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q12\uff1aView \u7684\u7ed8\u5236\u6d41\u7a0b\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4e09\u4e2a\u4f9d\u6b21\u8fdb\u884c\u7684\u9636\u6bb5\uff0c\u7531 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">ViewRootImpl<\/code> \u9a71\u52a8\uff1a<\/p>\n<ol style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">measure<\/strong>\uff1a\u9012\u5f52\u6d4b\u91cf\uff0c\u7236 View \u901a\u8fc7 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">MeasureSpec<\/code>\uff08\u6a21\u5f0f + \u5c3a\u5bf8\uff09\u628a\u7ea6\u675f\u4f20\u7ed9\u5b50 View\uff0c\u5b50 View \u8ba1\u7b97\u51fa\u81ea\u5df1\u7684\u5bbd\u9ad8\u5e76\u8c03\u7528 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">setMeasuredDimension()<\/code>\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">layout<\/strong>\uff1a\u7236 View \u8c03\u7528\u5b50 View \u7684 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">layout(l,t,r,b)<\/code>\uff0c\u786e\u5b9a\u56db\u4e2a\u9876\u70b9\u4f4d\u7f6e\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">draw<\/strong>\uff1a\u4f9d\u6b21\u7ed8\u5236<strong style=\"color:#0f1c2e;font-weight:600\">\u80cc\u666f \u2192 \u81ea\u8eab\uff08onDraw\uff09\u2192 \u5b50 View\uff08dispatchDraw\uff09\u2192 \u6eda\u52a8\u6761\u7b49\u88c5\u9970<\/strong>\u3002<\/li>\n<\/ol>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">MeasureSpec<\/code> \u4e09\u79cd\u6a21\u5f0f\u5fc5\u987b\u8bb0\u4f4f\uff1a<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">EXACTLY<\/code>\uff08\u7cbe\u786e\u503c\u6216 match_parent\uff09\u3001<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">AT_MOST<\/code>\uff08wrap_content\uff0c\u4e0a\u9650\u4e3a\u7236\u7684\u5269\u4f59\u7a7a\u95f4\uff09\u3001<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">UNSPECIFIED<\/code>\uff08\u65e0\u7ea6\u675f\uff0c\u5e38\u89c1\u4e8e ScrollView \u5185\u90e8\u3001ListView \u6d4b\u91cf\uff09\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q13\uff1a\u4e3a\u4ec0\u4e48\u81ea\u5b9a\u4e49 View \u7684 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">wrap_content<\/code> \u5931\u6548\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u56e0\u4e3a <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">View<\/code> \u7684\u9ed8\u8ba4 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">onMeasure()<\/code> \u5b9e\u73b0\u91cc\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u53ea\u8981\u4e0d\u662f <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">EXACTLY<\/code> \u6a21\u5f0f\uff0c\u5c31\u76f4\u63a5\u628a\u7236\u5bb9\u5668\u7ed9\u7684\u6700\u5927\u53ef\u7528\u5c3a\u5bf8\u5f53\u6210\u81ea\u5df1\u7684\u5c3a\u5bf8<\/strong>\u2014\u2014\u4e8e\u662f <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">wrap_content<\/code> \u8868\u73b0\u5f97\u548c <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">match_parent<\/code> \u4e00\u6837\u3002\u89e3\u6cd5\u662f\u91cd\u5199 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">onMeasure<\/code>\uff0c\u5728 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">AT_MOST<\/code> \u6a21\u5f0f\u4e0b<strong style=\"color:#0f1c2e;font-weight:600\">\u81ea\u5df1\u7b97\u51fa\u5185\u5bb9\u6240\u9700\u5c3a\u5bf8<\/strong>\u518d <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">setMeasuredDimension()<\/code>\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q14\uff1aUI \u5361\u987f\u7684\u539f\u56e0\u4e0e\u6392\u67e5\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u6839\u56e0\u5c31\u4e24\u7c7b\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u4e3b\u7ebf\u7a0b\u505a\u4e86\u8017\u65f6\u64cd\u4f5c<\/strong>\uff08IO\u3001\u5927\u91cf\u8ba1\u7b97\u3001JSON \u89e3\u6790\u3001\u6570\u636e\u5e93\u67e5\u8be2\uff09\uff0c\u6216<strong style=\"color:#0f1c2e;font-weight:600\">\u7ed8\u5236\u672c\u8eab\u592a\u91cd<\/strong>\uff08\u5e03\u5c40\u5c42\u7ea7\u8fc7\u6df1\u3001\u8fc7\u5ea6\u7ed8\u5236\u3001\u9891\u7e41\u89e6\u53d1 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">requestLayout<\/code>\uff09\u3002<\/p>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u6392\u67e5\u624b\u6bb5\uff1aSystrace \/ Perfetto \u770b\u4e3b\u7ebf\u7a0b\u5e27\u8017\u65f6\u3001Layout Inspector \u770b\u5c42\u7ea7\u3001GPU \u8fc7\u5ea6\u7ed8\u5236\u8c03\u8bd5\u770b\u53e0\u52a0\u5c42\u6570\u3001<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">Choreographer.FrameCallback<\/code> \u505a\u7ebf\u4e0a\u5e27\u7387\u76d1\u63a7\u3001<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">BlockedCanary<\/code> \u4e4b\u7c7b\u5de5\u5177\u6293\u6162\u65b9\u6cd5\u3002<\/p>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #6b5ce7;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-5\">\u4e94\u3001Jetpack Compose\uff1a2026 \u5e74\u7684\u5fc5\u8003\u533a<\/h2>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q15\uff1aCompose \u548c\u4f20\u7edf View \u4f53\u7cfb\u7684\u6839\u672c\u533a\u522b\uff1f<\/h3>\n<ul style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u58f0\u660e\u5f0f<\/strong>\uff1aUI \u662f\u72b6\u6001\u7684\u51fd\u6570 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">UI = f(state)<\/code>\uff0c\u72b6\u6001\u53d8\u4e86\u81ea\u52a8\u91cd\u7ec4\uff0c\u4e0d\u9700\u8981\u624b\u52a8 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">setText()<\/code>\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u65e0 View \u5b9e\u4f8b<\/strong>\uff1aCompose \u7528 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">LayoutNode<\/code> \u6811\u800c\u975e <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">View<\/code> \u6811\uff0c\u6ca1\u6709 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">findViewById<\/code>\uff0c\u4e5f\u4e0d\u9700\u8981 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">ViewHolder<\/code>\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u667a\u80fd\u91cd\u7ec4<\/strong>\uff1a\u53ea\u6709\u8bfb\u53d6\u4e86\u53d8\u5316\u72b6\u6001\u7684\u53ef\u7ec4\u5408\u9879\u624d\u4f1a\u91cd\u7ec4\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u672a\u8bfb\u53d6\u7684\u90e8\u5206\u4f1a\u88ab\u8df3\u8fc7<\/strong>\uff08\u8fd9\u662f&#8221;\u91cd\u7ec4\u4f5c\u7528\u57df&#8221;\u7684\u610f\u4e49\uff09\u3002<\/li>\n<\/ul>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q16\uff1a\u4ec0\u4e48\u662f&#8221;\u72b6\u6001\u63d0\u5347&#8221;\uff08State Hoisting\uff09\uff1f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u628a\u72b6\u6001\u4ece\u53ef\u7ec4\u5408\u9879\u5185\u90e8\u79fb\u5230<strong style=\"color:#0f1c2e;font-weight:600\">\u8c03\u7528\u65b9<\/strong>\uff0c\u8ba9\u53ef\u7ec4\u5408\u9879\u53d8\u6210<strong style=\"color:#0f1c2e;font-weight:600\">\u65e0\u72b6\u6001\uff08stateless\uff09\u7684\u7eaf\u51fd\u6570<\/strong>\uff1a\u53c2\u6570\u8fdb\u3001\u4e8b\u4ef6\u51fa\u3002<\/p>\n<pre style=\"background:#0f1a2b;color:#dbe6f5;border-radius:12px;padding:18px 20px;overflow-x:auto;font-size:13.6px;line-height:1.78;margin:22px 0;border:1px solid #1e2c42;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace\"><code style=\"background:none;border:none;color:inherit;padding:0;font-size:inherit;font-family:inherit\">\/\/ \u53cd\u4f8b\uff1a\u72b6\u6001\u85cf\u5728\u5185\u90e8\uff0c\u8c03\u7528\u65b9\u65e0\u6cd5\u63a7\u5236\u3001\u96be\u4ee5\u590d\u7528\u548c\u6d4b\u8bd5\n@Composable\nfun Counter() {\n    var count by remember { mutableIntStateOf(0) }\n    Button(onClick = { count++ }) { Text(\"$count\") }\n}\n\n\/\/ \u6b63\u4f8b\uff1a\u72b6\u6001\u63d0\u5347\uff0c\u7ec4\u4ef6\u53d8\u6210\u65e0\u72b6\u6001\u7684\n@Composable\nfun Counter(count: Int, onIncrement: () -&gt; Unit) {\n    Button(onClick = onIncrement) { Text(\"$count\") }\n}\n\n\/\/ \u8c03\u7528\u65b9\u6301\u6709\u72b6\u6001\uff0c\u5355\u4e00\u6570\u636e\u6e90\n@Composable\nfun CounterScreen() {\n    var count by remember { mutableIntStateOf(0) }\n    Counter(count = count, onIncrement = { count++ })\n}<\/code><\/pre>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4ef7\u503c\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u5355\u4e00\u6570\u636e\u6e90\u3001\u53ef\u590d\u7528\u3001\u53ef\u9884\u89c8\u3001\u53ef\u6d4b\u8bd5<\/strong>\uff0c\u5e76\u4e14\u4fbf\u4e8e\u628a\u72b6\u6001\u653e\u8fdb <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">ViewModel<\/code> \u4ece\u800c\u5728\u914d\u7f6e\u53d8\u66f4\u540e\u4fdd\u7559\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #6b5ce740\">Q17\uff1a<code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">remember<\/code> \u548c <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">rememberSaveable<\/code> \u7684\u533a\u522b\uff1f<\/h3>\n<ul style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">remember<\/code><\/strong>\uff1a\u53ea\u5728<strong style=\"color:#0f1c2e;font-weight:600\">\u91cd\u7ec4<\/strong>\u4e4b\u95f4\u4fdd\u7559\uff0c\u914d\u7f6e\u53d8\u66f4\uff08\u65cb\u8f6c\u5c4f\u5e55\uff09\u6216\u8fdb\u7a0b\u91cd\u5efa\u540e\u4f1a\u4e22\u5931\u3002<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\"><code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">rememberSaveable<\/code><\/strong>\uff1a\u628a\u72b6\u6001\u5199\u5165 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">Bundle<\/code>\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u80fd\u8de8\u914d\u7f6e\u53d8\u66f4\u548c\u8fdb\u7a0b\u91cd\u5efa\u6062\u590d<\/strong>\u3002\u8981\u6c42\u5bf9\u8c61\u53ef\u653e\u5165 Bundle\uff0c\u6216\u7528\u81ea\u5b9a\u4e49 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">Saver<\/code>\u3002<\/li>\n<\/ul>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #6b5ce7;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-6\">\u516d\u3001\u5c0f\u7ed3<\/h2>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">Android \u539f\u7406\u9898\u7684\u8003\u5bdf\u4e3b\u7ebf\u662f<strong style=\"color:#0f1c2e;font-weight:600\">&#8220;\u673a\u5236 + \u53d6\u820d + \u8e29\u5751&#8221;<\/strong>\uff1aHandler \u8003\u7684\u662f\u6d88\u606f\u5faa\u73af\u4e0e\u7ebf\u7a0b\u6a21\u578b\uff0cBinder \u8003\u7684\u662f\u8de8\u8fdb\u7a0b\u901a\u4fe1\u5728\u6027\u80fd\u4e0e\u5b89\u5168\u4e0a\u7684\u6743\u8861\uff0c\u7ec4\u4ef6\u8003\u7684\u662f\u751f\u547d\u5468\u671f\u4e0e\u540e\u53f0\u9650\u5236\uff0cCompose \u8003\u7684\u5219\u662f<strong style=\"color:#0f1c2e;font-weight:600\">\u6709\u6ca1\u6709\u771f\u6b63\u4ece\u547d\u4ee4\u5f0f\u601d\u7ef4\u8f6c\u5230\u58f0\u660e\u5f0f\u601d\u7ef4<\/strong>\u3002<\/p>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u51c6\u5907\u7b56\u7565\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u6bcf\u6761\u4e3b\u7ebf\u51c6\u5907\u4e00\u4e2a\u81ea\u5df1\u771f\u8e29\u8fc7\u7684\u5751<\/strong>\u2014\u2014\u6bd4\u5982&#8221;\u5ef6\u65f6\u6d88\u606f\u5bfc\u81f4 Activity \u6cc4\u6f0f\uff0c\u6700\u540e\u7528\u5f31\u5f15\u7528\u52a0 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">onDestroy<\/code> \u6e05\u7406\u89e3\u51b3\u7684&#8221;\u3002\u8fd9\u7c7b\u5177\u4f53\u7ecf\u5386\u6bd4\u5b8c\u6574\u80cc\u8bf5\u6e90\u7801\u66f4\u80fd\u62ff\u5230\u9ad8\u5206\u3002<\/p>\n<hr style=\"border:none;border-top:1px solid #eaeef4;margin:34px 0\">\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\"><em style=\"color:#5a6b85;font-style:normal;background:#6b5ce71f;padding:1px 4px;border-radius:4px\">\u53c2\u8003\uff1a<a href=\"https:\/\/developer.android.com\/guide\" target=\"_blank\" rel=\"noopener\" style=\"color:#6b5ce7;text-decoration:none;border-bottom:1px solid #6b5ce766;transition:opacity .15s\">Android \u5f00\u53d1\u8005\u6307\u5357<\/a>\u3001<a href=\"https:\/\/developer.android.com\/develop\/ui\/compose\" target=\"_blank\" rel=\"noopener\" style=\"color:#6b5ce7;text-decoration:none;border-bottom:1px solid #6b5ce766;transition:opacity .15s\">Jetpack Compose \u6587\u6863<\/a>\u3001<a href=\"https:\/\/source.android.com\/docs\/core\/architecture\" target=\"_blank\" rel=\"noopener\" style=\"color:#6b5ce7;text-decoration:none;border-bottom:1px solid #6b5ce766;transition:opacity .15s\">AOSP \u67b6\u6784\u6587\u6863<\/a>\u3002\u884c\u4e3a\u968f Android \u7248\u672c\u6f14\u8fdb\uff0c\u6d89\u53ca\u540e\u53f0\u9650\u5236\u4e0e\u6743\u9650\u7684\u90e8\u5206\u8bf7\u4ee5\u76ee\u6807 API \u7b49\u7ea7\u7684\u5b98\u65b9\u6587\u6863\u4e3a\u51c6\u3002<\/em><\/p>\n<div style=\"margin:42px 0 0;padding:22px 0 0;border-top:1px solid #eaeef4\">\n<div style=\"font-size:13px;color:#93a1b5;letter-spacing:1px;margin-bottom:12px\">\u6807\u7b7e<\/div>\n<p><span style=\"display:inline-block;background:#f3f6fa;border:1px solid #e4eaf2;color:#5b6c85;font-size:13px;padding:5px 12px;border-radius:999px;margin:0 8px 8px 0\">#Android \u9762\u8bd5\u9898<\/span><span style=\"display:inline-block;background:#f3f6fa;border:1px solid #e4eaf2;color:#5b6c85;font-size:13px;padding:5px 12px;border-radius:999px;margin:0 8px 8px 0\">#Handler<\/span><span style=\"display:inline-block;background:#f3f6fa;border:1px solid #e4eaf2;color:#5b6c85;font-size:13px;padding:5px 12px;border-radius:999px;margin:0 8px 8px 0\">#Binder<\/span><span style=\"display:inline-block;background:#f3f6fa;border:1px solid #e4eaf2;color:#5b6c85;font-size:13px;padding:5px 12px;border-radius:999px;margin:0 8px 8px 0\">#\u9762\u8bd5<\/span><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Android \u9762\u8bd5\u7684\u539f\u7406\u9898\u6709\u975e\u5e38\u7a33\u5b9a\u7684\u6838\u5fc3\u533a\u3002\u672c\u6587\u9010\u9898\u7ed9\u51fa\u6807\u51c6\u7b54\u6cd5\u3001\u8ffd\u95ee\u9677\u9631\u4e0e\u9762\u8bd5\u5b98\u60f3\u542c\u7684\u90a3\u53e5\u8bdd\uff0c\u8986\u76d6 Handler \u4e3a\u4ec0\u4e48\u4e0d\u4f1a ANR\u3001Binder \u4e3a\u4ec0\u4e48\u53ea\u9700\u4e00\u6b21\u62f7\u8d1d\u3001\u542f\u52a8\u6a21\u5f0f\u5dee\u5f02\u3001\u540e\u53f0\u9650\u5236\uff0c\u4ee5\u53ca Compose \u7684\u72b6\u6001\u63d0\u5347\u3002<\/p>\n","protected":false},"author":1,"featured_media":242,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,11],"tags":[118,120,119,66],"class_list":["post-244","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mobile-question-bank","category-question-bank","tag-android-","tag-binder","tag-handler","tag-66"],"_links":{"self":[{"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/comments?post=244"}],"version-history":[{"count":0,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/posts\/244\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/media\/242"}],"wp:attachment":[{"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/media?parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/categories?post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/tags?post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}