{"id":108,"date":"2026-08-19T21:43:44","date_gmt":"2026-08-19T13:43:44","guid":{"rendered":"http:\/\/xuanyuan123.site\/wordPress\/2026\/08\/19\/androidx-fragment-%e9%85%8d%e7%bd%ae%e5%8f%98%e6%9b%b4%e4%b8%8b%e5%ae%9e%e4%be%8b%e4%bf%9d%e7%95%99%e4%b8%8e-dialog-%e5%9b%9e%e8%b0%83%e6%8e%92%e6%9f%a5%e8%ae%b0%e5%bd%95\/"},"modified":"2026-08-19T21:48:08","modified_gmt":"2026-08-19T13:48:08","slug":"androidx-fragment-%e9%85%8d%e7%bd%ae%e5%8f%98%e6%9b%b4%e4%b8%8b%e5%ae%9e%e4%be%8b%e4%bf%9d%e7%95%99%e4%b8%8e-dialog-%e5%9b%9e%e8%b0%83%e6%8e%92%e6%9f%a5%e8%ae%b0%e5%bd%95","status":"publish","type":"post","link":"http:\/\/xuanyuan123.site\/wordPress\/2026\/08\/19\/androidx-fragment-%e9%85%8d%e7%bd%ae%e5%8f%98%e6%9b%b4%e4%b8%8b%e5%ae%9e%e4%be%8b%e4%bf%9d%e7%95%99%e4%b8%8e-dialog-%e5%9b%9e%e8%b0%83%e6%8e%92%e6%9f%a5%e8%ae%b0%e5%bd%95\/","title":{"rendered":"AndroidX Fragment \u914d\u7f6e\u53d8\u66f4\u4e0b\u5b9e\u4f8b\u4fdd\u7559\u4e0e Dialog \u56de\u8c03\u6392\u67e5\u8bb0\u5f55"},"content":{"rendered":"<style>\n.tech-article {\n    line-height: 1.75;\n    color: #24292f;\n    font-size: 15px;\n}\n.tech-article h2 {\n    font-size: 1.3rem !important;\n    font-weight: 600 !important;\n    margin-top: 1.5rem !important;\n    margin-bottom: 0.4rem !important;\n    padding-bottom: 0.3rem !important;\n    border-bottom: 1px solid #eaecef !important;\n    line-height: 1.3 !important;\n}\n.tech-article h3 {\n    font-size: 1.12rem !important;\n    font-weight: 600 !important;\n    margin-top: 1.1rem !important;\n    margin-bottom: 0.35rem !important;\n    line-height: 1.35 !important;\n}\n.tech-article h4 {\n    font-size: 1.02rem !important;\n    font-weight: 600 !important;\n    margin-top: 1.0rem !important;\n    margin-bottom: 0.3rem !important;\n}\n.tech-article p {\n    margin-top: 0 !important;\n    margin-bottom: 0.65rem !important;\n    line-height: 1.75 !important;\n}\n.tech-article ul, .tech-article ol {\n    margin-top: 0 !important;\n    margin-bottom: 0.65rem !important;\n    padding-left: 1.5rem !important;\n}\n.tech-article li {\n    margin-bottom: 0.2rem !important;\n    line-height: 1.65 !important;\n}\n.tech-article pre {\n    background-color: #f6f8fa !important;\n    border: 1px solid #e1e4e8 !important;\n    border-radius: 6px !important;\n    padding: 12px 16px !important;\n    margin: 0.65rem 0 !important;\n    overflow-x: auto !important;\n    font-size: 13.5px !important;\n    line-height: 1.55 !important;\n}\n.tech-article code {\n    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace !important;\n}\n.tech-article p code, .tech-article li code, .tech-article td code {\n    background-color: rgba(175, 184, 193, 0.2) !important;\n    padding: 0.2em 0.4em !important;\n    border-radius: 4px !important;\n    font-size: 88% !important;\n    color: #c7254e !important;\n}\n.tech-article blockquote {\n    margin: 0.65rem 0 !important;\n    padding: 8px 16px !important;\n    border-left: 4px solid #0969da !important;\n    background-color: #f6f8fa !important;\n    color: #57606a !important;\n}\n.tech-article blockquote p {\n    margin-bottom: 0 !important;\n}\n.tech-article table {\n    border-collapse: collapse !important;\n    width: 100% !important;\n    margin: 0.65rem 0 !important;\n    font-size: 14px !important;\n}\n.tech-article th, .tech-article td {\n    border: 1px solid #d0d7de !important;\n    padding: 6px 12px !important;\n}\n.tech-article th {\n    background-color: #f6f8fa !important;\n    font-weight: 600 !important;\n}\n.tech-article hr {\n    margin: 1.0rem 0 !important;\n    border: 0 !important;\n    border-top: 1px solid #eaecef !important;\n}\n<\/style>\n<div class=\"tech-article\">\n<h2>\u80cc\u666f<\/h2>\n<p>\u5728\u4e00\u4e2a Android \u5e94\u7528\u4e2d\uff0c\u67d0\u4e2a\u201c\u8d26\u53f7\u89e3\u7ed1\u786e\u8ba4\u5f39\u7a97\u201d\u5927\u81f4\u662f\u4e0b\u9762\u8fd9\u79cd\u5199\u6cd5\uff0c\u786e\u8ba4\u52a8\u4f5c\u4f9d\u8d56 Fragment \u7684\u4e00\u4e2a\u6210\u5458\u53d8\u91cf\uff1a<\/p>\n<pre><code class=\"language-kotlin\">class ConfirmDialogFragment : DialogFragment() {\n\n    private var onConfirm: (() -&gt; Unit)? = null\n\n    fun setOnConfirmListener(listener: () -&gt; Unit): ConfirmDialogFragment {\n        onConfirm = listener\n        return this\n    }\n\n    private fun onConfirmClick() {\n        onConfirm?.invoke()\n    }\n}\n<\/code><\/pre>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u771f\u6b63\u89e6\u53d1\u89e3\u7ed1\u903b\u8f91\u7684\u4e0d\u662f <code>arguments<\/code> \u6216 <code>savedInstanceState<\/code>\uff0c\u800c\u662f Fragment \u5b9e\u4f8b\u91cc\u7684\u5b57\u6bb5 <code>onConfirm<\/code>\u3002<\/p>\n<p>\u6700\u521d\u505a MR review \u65f6\uff0c\u63d0\u51fa\u4e86\u4e00\u4e2a\u6f5c\u5728\u98ce\u9669\uff1a<\/p>\n<blockquote>\n<p>\u5982\u679c\u8bbe\u5907\u5728\u5f39\u51fa\u786e\u8ba4\u5f39\u7a97\u540e\u53d1\u751f\u6a2a\u7ad6\u5c4f\u5207\u6362\uff0c\u5bbf\u4e3b Activity \u91cd\u5efa\uff0c\u90a3\u4e48\u5f39\u7a97\u91cc\u7684 <code>onConfirm<\/code> \u7531\u4e8e\u4e0d\u5728 <code>Bundle<\/code> \u4e2d\uff0c\u7406\u8bba\u4e0a\u5e94\u8be5\u4e22\u5931\u3002\u6b64\u65f6\u70b9\u51fb\u201c\u786e\u8ba4\u89e3\u7ed1\u201d\uff0c\u5e94\u8be5\u53ea <code>dismiss<\/code>\uff0c\u4e0d\u5e94\u7ee7\u7eed\u6267\u884c\u89e3\u7ed1\u903b\u8f91\u3002<\/p>\n<\/blockquote>\n<p>\u4f46\u5b9e\u9645\u624b\u6d4b\u53d1\u73b0\uff1a<\/p>\n<ol>\n<li>\u7ad6\u5c4f\u6253\u5f00\u89e3\u7ed1\u786e\u8ba4\u5f39\u7a97<\/li>\n<li>\u5207\u6362\u5230\u6a2a\u5c4f<\/li>\n<li>\u70b9\u51fb\u201c\u89e3\u7ed1\u201d<\/li>\n<li>\u89e3\u7ed1\u4f9d\u7136\u751f\u6548<\/li>\n<\/ol>\n<p>\u8fd9\u548c\u6700\u521d\u7684\u9759\u6001\u5206\u6790\u7ed3\u8bba\u77db\u76fe\uff0c\u56e0\u6b64\u9700\u8981\u505a\u4e00\u6b21\u5b8c\u6574\u6392\u67e5\u3002<\/p>\n<hr \/>\n<h2>\u53d1\u751f\u573a\u666f<\/h2>\n<p>\u95ee\u9898\u53d1\u751f\u65f6\uff0c\u786e\u8ba4\u89e3\u7ed1\u5f39\u7a97\u662f\u6302\u5728\u5e94\u7528\u4e3b\u754c\u9762 Activity \u7684 <code>supportFragmentManager<\/code> \u4e0b\u7684\u3002<\/p>\n<p>\u5b9e\u9645\u94fe\u8def\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-text\">\u4e3b\u754c\u9762 Activity\n  \u2514\u2500 \u9996\u9875 Fragment\n       \u2514\u2500 \u5185\u5bb9 Fragment\n            \u2514\u2500 \u6253\u5f00\u8d26\u53f7\u7ba1\u7406 Dialog\n                 \u2514\u2500 \u70b9\u51fb\u89e3\u7ed1\n                      \u2514\u2500 \u6253\u5f00\u786e\u8ba4\u89e3\u7ed1 Dialog\n<\/code><\/pre>\n<p>\u8fd9\u610f\u5473\u7740\uff1a<\/p>\n<ul>\n<li>\u5bbf\u4e3b <code>FragmentManager<\/code> \u6765\u81ea\u4e3b\u754c\u9762 Activity<\/li>\n<li>\u786e\u8ba4\u89e3\u7ed1 Dialog \u662f\u6302\u5728\u4e3b\u754c\u9762 Activity \u7684 <code>supportFragmentManager<\/code> \u4e0b\u7684<\/li>\n<\/ul>\n<p>\u800c\u8fd9\u4e2a\u4e3b\u754c\u9762 Activity \u5728 manifest \u4e2d\u5e76\u6ca1\u6709\u58f0\u660e <code>configChanges<\/code>\uff1a<\/p>\n<pre><code class=\"language-xml\">&lt;activity\n    android:name=&quot;...&quot;\n    android:launchMode=&quot;singleInstance&quot;\n    android:theme=&quot;...&quot; \/&gt;\n<\/code><\/pre>\n<p>\u56e0\u6b64\uff0c\u6309\u6807\u51c6 Android \u8bed\u4e49\uff0c\u6a2a\u7ad6\u5c4f\u5207\u6362\u65f6\u5b83\u5e94\u8be5\u8d70 <code>destroy<\/code> + <code>recreate<\/code>\u3002<\/p>\n<hr \/>\n<h2>\u65e5\u5fd7\u65b9\u6848<\/h2>\n<p>\u4e3a\u4e86\u76f4\u63a5\u56de\u7b54\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ea\u52a0\u4e86\u6700\u5c0f\u5fc5\u8981\u7684\u4e00\u7ec4\u65e5\u5fd7\uff0c\u7edf\u4e00 tag \u4e3a\uff1a<code>AccountRotateDbg<\/code><\/p>\n<ul>\n<li><strong>\u4e3b\u754c\u9762 Activity<\/strong>\uff1a<code>onCreate<\/code>\u3001<code>onDestroy<\/code><\/li>\n<li><strong>\u786e\u8ba4\u89e3\u7ed1 Dialog<\/strong>\uff1a<code>setOnConfirmListener<\/code>\u3001<code>onCreateView<\/code>\u3001<code>onDestroyView<\/code>\u3001<code>onDestroy<\/code>\u3001\u786e\u8ba4\u70b9\u51fb\u65f6 <code>onConfirm<\/code> \u662f\u5426\u5b58\u5728<\/li>\n<li><strong>\u89e3\u7ed1\u903b\u8f91\u5165\u53e3<\/strong>\uff1a<code>unbindAccount<\/code>\u3001<code>logout<\/code><\/li>\n<\/ul>\n<p>\u76ee\u6807\u53ea\u6709\u4e09\u4e2a\uff1a<\/p>\n<ol>\n<li>Activity \u662f\u5426\u771f\u7684\u91cd\u5efa<\/li>\n<li>\u786e\u8ba4\u89e3\u7ed1 Dialog \u662f\u5426\u8fd8\u662f\u540c\u4e00\u4e2a\u5b9e\u4f8b<\/li>\n<li>\u70b9\u51fb\u201c\u89e3\u7ed1\u201d\u65f6\u662f\u5426\u771f\u7684\u6267\u884c\u4e86\u89e3\u7ed1\u903b\u8f91<\/li>\n<\/ol>\n<hr \/>\n<h2>\u5b9e\u6d4b\u65e5\u5fd7<\/h2>\n<p>\u7528\u6237\u7ed9\u51fa\u7684\u5173\u952e\u65e5\u5fd7\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-log\">2026-08-19 16:02:08.035  AccountRotateDbg  onCreate instance=45440906 savedState=false orientation=1\n2026-08-19 16:02:59.865  AccountRotateDbg  unbindAccount provider=googleCalendar accountId=95800185641911bec36e572a057a9383\n2026-08-19 16:02:59.867  AccountRotateDbg  setOnConfirmListener instance=103017373 onConfirmSet=true\n2026-08-19 16:02:59.870  AccountRotateDbg  onCreate instance=103017373 savedState=false onConfirmSet=true\n2026-08-19 16:02:59.871  AccountRotateDbg  onCreateView instance=103017373 savedState=false onConfirmSet=true\n2026-08-19 16:03:05.812  AccountRotateDbg  onDestroy instance=45440906 isFinishing=false\n2026-08-19 16:03:05.830  AccountRotateDbg  onDestroyView instance=103017373 onConfirmSet=true\n2026-08-19 16:03:05.925  AccountRotateDbg  onCreate instance=197475998 savedState=true orientation=2\n2026-08-19 16:03:06.365  AccountRotateDbg  onCreateView instance=103017373 savedState=true onConfirmSet=true\n2026-08-19 16:03:09.977  AccountRotateDbg  confirmClick instance=103017373 onConfirmSet=true -&gt; invoke logout\n2026-08-19 16:03:09.991  AccountRotateDbg  logout provider=googleCalendar accountId=95800185641911bec36e572a057a9383\n2026-08-19 16:03:10.008  AccountRotateDbg  onDestroyView instance=103017373 onConfirmSet=true\n2026-08-19 16:03:10.009  AccountRotateDbg  onDestroy instance=103017373 onConfirmSet=true\n<\/code><\/pre>\n<hr \/>\n<h2>\u7ed3\u8bba<\/h2>\n<h3>1. \u4e3b\u754c\u9762 Activity \u786e\u5b9e\u88ab\u9500\u6bc1\u91cd\u5efa\u4e86<\/h3>\n<p>\u8fd9\u4e00\u70b9\u7531\u4e0b\u9762\u4e24\u884c\u76f4\u63a5\u8bc1\u660e\uff1a<\/p>\n<pre><code class=\"language-log\">onDestroy instance=45440906 isFinishing=false\nonCreate  instance=197475998 savedState=true orientation=2\n<\/code><\/pre>\n<p>\u8bf4\u660e\u65cb\u8f6c\u65f6\u786e\u5b9e\u4e0d\u662f\u7b80\u5355\u6539\u65b9\u5411\uff0c\u800c\u662f\u5bbf\u4e3b Activity \u8d70\u4e86\u6807\u51c6 recreate \u6d41\u7a0b\u3002<\/p>\n<h3>2. \u786e\u8ba4\u89e3\u7ed1 Dialog \u5b9e\u4f8b\u6ca1\u6709\u53d8<\/h3>\n<p>\u786e\u8ba4\u89e3\u7ed1 Dialog \u4ece\u663e\u793a\u5230\u65cb\u8f6c\u540e\u518d\u5230\u70b9\u51fb\u786e\u8ba4\uff0c\u4e00\u76f4\u662f\u540c\u4e00\u4e2a\u5b9e\u4f8b\uff1a<code>instance=103017373<\/code><\/p>\n<p>\u65e5\u5fd7\u91cc\u7684\u5173\u952e\u6a21\u5f0f\u662f\uff1a<\/p>\n<ul>\n<li>\u65cb\u8f6c\u524d\u6709 <code>onCreateView<\/code><\/li>\n<li>\u65cb\u8f6c\u65f6\u53ea\u770b\u5230 <code>onDestroyView<\/code><\/li>\n<li>\u65cb\u8f6c\u540e\u53c8\u662f\u540c\u4e00\u4e2a instance \u7684 <code>onCreateView<\/code><\/li>\n<li>\u4e2d\u95f4\u6ca1\u6709\u51fa\u73b0 <code>onDestroy<\/code><\/li>\n<\/ul>\n<p>\u8fd9\u8bf4\u660e\u65cb\u8f6c\u65f6\u53d1\u751f\u7684\u662f\uff1aFragment \u5b9e\u4f8b\u88ab\u4fdd\u7559\uff0c\u53ea\u662f View \u88ab\u9500\u6bc1\u5e76\u91cd\u65b0\u521b\u5efa\u3002<\/p>\n<h3>3. onConfirm \u6ca1\u4e22\uff0c\u6240\u4ee5\u89e3\u7ed1\u903b\u8f91\u4f1a\u7ee7\u7eed\u6267\u884c<\/h3>\n<p>\u65e5\u5fd7\u660e\u786e\u663e\u793a\uff1a<\/p>\n<pre><code class=\"language-log\">confirmClick instance=103017373 onConfirmSet=true -&gt; invoke logout\nlogout ...\n<\/code><\/pre>\n<hr \/>\n<h2>\u4e3a\u4ec0\u4e48\u4f1a\u8fd9\u6837<\/h2>\n<p>\u8fd9\u6b21\u6392\u67e5\u7684\u6838\u5fc3\u6536\u83b7\u662f\uff1a<\/p>\n<blockquote>\n<p>\u5728\u914d\u7f6e\u53d8\u66f4\u65f6\uff0c\u88ab\u9500\u6bc1\u91cd\u5efa\u7684\u662f\u5bbf\u4e3b Activity\uff0c\u4f46 FragmentManager \u53ef\u80fd\u4f1a\u4fdd\u7559\u5df2\u7ecf\u52a0\u5165\u7ba1\u7406\u5668\u7684 Fragment \u5b9e\u4f8b\uff0c\u53ea\u91cd\u5efa\u5b83\u4eec\u7684 View\u3002<\/p>\n<\/blockquote>\n<p>\u8fd9\u6b63\u662f AndroidX FragmentManager \u5728\u914d\u7f6e\u53d8\u66f4\u65f6\u7684\u5178\u578b\u884c\u4e3a\uff1a<\/p>\n<ol>\n<li>\u65e7 Activity \u9500\u6bc1<\/li>\n<li>FragmentManager \u901a\u8fc7\u975e\u914d\u7f6e\u5b9e\u4f8b\u673a\u5236\u4fdd\u7559 Fragment \u5bf9\u8c61<\/li>\n<li>\u65b0 Activity \u521b\u5efa<\/li>\n<li>\u540c\u4e00\u4e2a Fragment \u5b9e\u4f8b\u91cd\u65b0 attach \u5230\u65b0\u5bbf\u4e3b<\/li>\n<li>\u8d70\u65b0\u7684 <code>onCreateView()<\/code><\/li>\n<\/ol>\n<p>\u6240\u4ee5\u5728\u8fd9\u6b21\u573a\u666f\u91cc\uff1a<\/p>\n<ul>\n<li>\u786e\u8ba4\u89e3\u7ed1 Dialog \u5bf9\u8c61\u672c\u8eab\u6ca1\u6709\u6362<\/li>\n<li>\u5b83\u7684\u666e\u901a\u6210\u5458\u5b57\u6bb5 <code>onConfirm<\/code> \u4e5f\u5c31\u8fd8\u5728<\/li>\n<\/ul>\n<hr \/>\n<h2>\u8fd9\u662f\u5426\u8bf4\u660e\u5f53\u524d\u5b9e\u73b0\u5b8c\u5168\u5b89\u5168<\/h2>\n<p>\u4e0d\u80fd\u8fd9\u4e48\u4e0b\u7ed3\u8bba\u3002<\/p>\n<p>\u8fd9\u6b21\u53ea\u80fd\u8bf4\u660e\uff1a<\/p>\n<blockquote>\n<p>\u5728\u201c\u5bbf\u4e3b Activity \u56e0\u65cb\u8f6c\u91cd\u5efa\uff0c\u4f46\u786e\u8ba4\u89e3\u7ed1 Dialog \u5b9e\u4f8b\u88ab FragmentManager \u4fdd\u7559\u201d\u7684\u8fd9\u6761\u8def\u5f84\u91cc\uff0c<code>onConfirm<\/code> \u4e0d\u4f1a\u4e22\u3002<\/p>\n<\/blockquote>\n<p>\u4f46\u4e0b\u9762\u8fd9\u4e9b\u573a\u666f\u4ecd\u7136\u53ef\u80fd\u51fa\u95ee\u9898\uff1a<\/p>\n<ol>\n<li><strong>\u8fdb\u7a0b\u88ab\u7cfb\u7edf\u6740\u6389\u540e\u6062\u590d<\/strong><br \/>\n   &#8211; lambda \u4e0d\u4f1a\u88ab\u5e8f\u5217\u5316<br \/>\n   &#8211; <code>onConfirm<\/code> \u4ecd\u7136\u4f1a\u4e22<\/li>\n<li><strong>\u5f00\u53d1\u8005\u9009\u9879\u5f00\u542f\u201c\u4e0d\u4fdd\u7559\u6d3b\u52a8\u201d<\/strong><br \/>\n   &#8211; \u66f4\u5bb9\u6613\u89e6\u53d1\u771f\u6b63\u7684\u5b9e\u4f8b\u91cd\u5efa<\/li>\n<li><strong>\u67d0\u4e9b\u6062\u590d\u8def\u5f84\u5bfc\u81f4 Fragment \u4e0d\u662f\u4fdd\u7559\u65e7\u5b9e\u4f8b\uff0c\u800c\u662f\u91cd\u65b0 new<\/strong><br \/>\n   &#8211; \u6b64\u65f6 <code>onConfirm<\/code> \u4ecd\u7136\u4e0d\u4f1a\u56de\u6765<\/li>\n<\/ol>\n<p>\u56e0\u6b64\uff0c\u201c\u8fd9\u6b21\u6a2a\u7ad6\u5c4f\u6ca1\u95ee\u9898\u201d\u4e0d\u4ee3\u8868\u201c\u8fd9\u79cd\u5199\u6cd5\u5728\u6240\u6709\u6062\u590d\u573a\u666f\u90fd\u6ca1\u95ee\u9898\u201d\u3002<\/p>\n<hr \/>\n<h2>\u5de5\u7a0b\u5224\u65ad<\/h2>\n<p>\u5f53\u524d\u8fd9\u4e2a\u95ee\u9898\u4e0d\u9700\u8981\u56e0\u4e3a\u201c\u65cb\u8f6c\u5fc5\u73b0\u5f02\u5e38\u201d\u800c\u963b\u585e\uff0c\u56e0\u4e3a\u65e5\u5fd7\u5df2\u7ecf\u8bc1\u660e\uff1a\u5728\u8fd9\u6761\u5b9e\u9645\u590d\u73b0\u8def\u5f84\u91cc\uff0c\u6a2a\u7ad6\u5c4f\u540e\u89e3\u7ed1\u4ecd\u4f1a\u6b63\u5e38\u6267\u884c\u3002<\/p>\n<p>\u4f46\u4ece\u8bbe\u8ba1\u4e0a\uff0c\u4ecd\u7136\u6709\u6539\u8fdb\u7a7a\u95f4\u3002<\/p>\n<p>\u66f4\u7a33\u59a5\u7684\u5199\u6cd5\u4ecd\u7136\u662f\uff1a<\/p>\n<ul>\n<li>\u4e0d\u4f9d\u8d56\u786e\u8ba4\u5f39\u7a97\u5185\u5b58\u4e2d\u7684 lambda<\/li>\n<li>\u6539\u4e3a\u901a\u8fc7 <code>arguments<\/code> \u4f20\u5165\u5fc5\u8981\u53c2\u6570\uff0c\u4f8b\u5982\uff1a<\/li>\n<li><code>providerName<\/code><\/li>\n<li><code>accountId<\/code><\/li>\n<li><code>authFeature<\/code><\/li>\n<li>\u5728 Dialog \u5185\u76f4\u63a5\u6267\u884c logout action<\/li>\n<\/ul>\n<p>\u6216\u8005\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 <code>FragmentResult<\/code> \u56de\u4f20\u201c\u7528\u6237\u786e\u8ba4\u89e3\u7ed1\u201d<\/li>\n<li>\u5bbf\u4e3b\u6839\u636e\u53ef\u6062\u590d\u6570\u636e\u81ea\u884c\u5904\u7406<\/li>\n<\/ul>\n<p>\u8fd9\u6837\u624d\u80fd\u540c\u65f6\u8986\u76d6\uff1a<\/p>\n<ul>\n<li>\u914d\u7f6e\u53d8\u66f4<\/li>\n<li>\u8fdb\u7a0b\u91cd\u5efa<\/li>\n<li>\u66f4\u4e25\u683c\u7684\u7cfb\u7edf\u6062\u590d\u573a\u666f<\/li>\n<\/ul>\n<hr \/>\n<h2>\u8fd9\u6b21\u6392\u67e5\u7684\u7ecf\u9a8c<\/h2>\n<h3>1. \u751f\u547d\u5468\u671f\u95ee\u9898\u4e0d\u80fd\u53ea\u9760\u9759\u6001\u63a8\u65ad\uff0c\u5fc5\u8981\u65f6\u4e00\u5b9a\u8981\u6253\u65e5\u5fd7<\/h3>\n<p>\u8fd9\u4e2a\u95ee\u9898\u5982\u679c\u53ea\u770b\u4ee3\u7801\uff0c\u5f88\u5bb9\u6613\u5f97\u5230\u4e00\u4e2a\u201c\u7406\u8bba\u4e0a\u5e94\u8be5\u4e22 listener\u201d\u7684\u7b54\u6848\u3002<br \/>\n\u4f46\u65e5\u5fd7\u8bc1\u660e\uff1a<\/p>\n<ul>\n<li>Activity \u7684\u786e\u91cd\u5efa\u4e86<\/li>\n<li>Fragment \u5b9e\u4f8b\u5374\u88ab\u4fdd\u7559\u4e86<\/li>\n<\/ul>\n<p>\u8fd9\u7c7b\u95ee\u9898\u4e0d\u7528\u65e5\u5fd7\uff0c\u5f88\u5bb9\u6613\u8bef\u5224\u3002<\/p>\n<h3>2. onDestroyView() \u548c onDestroy() \u4e0d\u662f\u4e00\u56de\u4e8b<\/h3>\n<p>\u8fd9\u6b21\u6b63\u597d\u662f\u4e00\u4e2a\u975e\u5e38\u597d\u7684\u6848\u4f8b\uff1a<\/p>\n<ul>\n<li><code>onDestroyView()<\/code> \u53d1\u751f\u4e86<\/li>\n<li><code>onDestroy()<\/code> \u6ca1\u6709\u7acb\u5373\u53d1\u751f<\/li>\n<\/ul>\n<p>\u8bf4\u660e\uff1a<\/p>\n<ul>\n<li>View \u88ab\u9500\u6bc1\u4e86<\/li>\n<li>Fragment \u5b9e\u4f8b\u8fd8\u6d3b\u7740<\/li>\n<\/ul>\n<p>\u5728\u5206\u6790\u201c\u6210\u5458\u5b57\u6bb5\u662f\u5426\u4f1a\u4e22\u5931\u201d\u65f6\uff0c\u8fd9\u4e2a\u533a\u522b\u975e\u5e38\u5173\u952e\u3002<\/p>\n<hr \/>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u8fd9\u6b21\u5173\u4e8e\u201c\u786e\u8ba4\u89e3\u7ed1 Dialog \u5728\u6a2a\u7ad6\u5c4f\u5207\u6362\u4e0b\u7684\u884c\u4e3a\u201d\u7684\u6392\u67e5\uff0c\u6700\u7ec8\u7ed3\u8bba\u662f\uff1a<\/p>\n<ol>\n<li>\u5bbf\u4e3b\u4e3b\u754c\u9762 Activity \u5728\u65cb\u8f6c\u65f6\u786e\u5b9e\u91cd\u5efa<\/li>\n<li>\u786e\u8ba4\u89e3\u7ed1 Dialog \u5b9e\u4f8b\u88ab FragmentManager \u4fdd\u7559<\/li>\n<li>\u65cb\u8f6c\u65f6\u53ea\u91cd\u5efa\u4e86 Dialog \u7684 View<\/li>\n<li>\u56e0\u4e3a\u5b9e\u4f8b\u6ca1\u6362\uff0c\u5185\u5b58\u4e2d\u7684 <code>onConfirm<\/code> \u4ecd\u7136\u5b58\u5728<\/li>\n<li>\u6240\u4ee5\u6a2a\u5c4f\u540e\u70b9\u51fb\u201c\u89e3\u7ed1\u201d\uff0clogout \u4f9d\u7136\u4f1a\u6267\u884c<\/li>\n<\/ol>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff1a<\/p>\n<blockquote>\n<p>\u201c\u6a2a\u7ad6\u5c4f\u540e\u89e3\u7ed1\u4ecd\u7136\u751f\u6548\u201d\u4e0d\u662f\u5076\u7136\uff0c\u4e5f\u4e0d\u662f\u53e6\u4e00\u4e2a\u65b0 Dialog \u88ab\u91cd\u65b0\u8bbe\u7f6e\u4e86 listener\uff0c\u800c\u662f AndroidX FragmentManager \u5728\u914d\u7f6e\u53d8\u66f4\u65f6\u4fdd\u7559\u4e86\u539f Fragment \u5b9e\u4f8b\u3002<\/p>\n<\/blockquote>\n<p>\u4e0d\u8fc7\uff0c\u8fd9\u4e2a\u7ed3\u8bba\u53ea\u8986\u76d6\u5f53\u524d\u8fd9\u6761\u6062\u590d\u8def\u5f84\uff1b\u82e5\u8981\u4ece\u5de5\u7a0b\u8bbe\u8ba1\u4e0a\u5b8c\u5168\u7a33\u59a5\uff0c\u4ecd\u5efa\u8bae\u628a\u89e3\u7ed1\u52a8\u4f5c\u6539\u4e3a\u53ef\u6062\u590d\u7684\u53c2\u6570\u9a71\u52a8\uff0c\u800c\u4e0d\u662f\u4f9d\u8d56\u4e34\u65f6 lambda\u3002<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f \u5728\u4e00\u4e2a Android \u5e94\u7528\u4e2d\uff0c\u67d0\u4e2a\u201c\u8d26\u53f7\u89e3\u7ed1\u786e\u8ba4\u5f39\u7a97\u201d\u5927\u81f4\u662f\u4e0b\u9762\u8fd9\u79cd\u5199\u6cd5\uff0c\u786e\u8ba4\u52a8\u4f5c\u4f9d\u8d56 Fragmen [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"http:\/\/xuanyuan123.site\/wordPress\/wp-json\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/xuanyuan123.site\/wordPress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xuanyuan123.site\/wordPress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xuanyuan123.site\/wordPress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xuanyuan123.site\/wordPress\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":1,"href":"http:\/\/xuanyuan123.site\/wordPress\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":113,"href":"http:\/\/xuanyuan123.site\/wordPress\/wp-json\/wp\/v2\/posts\/108\/revisions\/113"}],"wp:attachment":[{"href":"http:\/\/xuanyuan123.site\/wordPress\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xuanyuan123.site\/wordPress\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xuanyuan123.site\/wordPress\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}