{"id":535,"date":"2015-04-21T19:30:22","date_gmt":"2015-04-21T11:30:22","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=535"},"modified":"2026-08-18T12:58:40","modified_gmt":"2026-08-18T04:58:40","slug":"%e7%90%86%e8%a7%a3activity%e7%94%9f%e5%91%bd%e5%91%a8%e6%9c%9f%e7%9a%84%e5%9b%9e%e8%b0%83","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=535","title":{"rendered":"\u7406\u89e3Activity\u751f\u547d\u5468\u671f\u7684\u56de\u8c03"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\">Activity \u751f\u547d\u5468\u671f\u53ef\u4ee5\u60f3\u6210\u4e00\u5ea7<strong>\u91d1\u5b57\u5854<\/strong>\uff1a\u7cfb\u7edf\u6309\u53f0\u9636\u8c03\u7528\u56de\u8c03\u3002\u65b0\u5efa\u5b9e\u4f8b\u65f6\u56de\u8c03\u628a\u72b6\u6001\u5f80\u4e0a\u63a8\uff1b\u5230\u5854\u5c16\u5c31\u662f\u524d\u53f0\u3001\u7528\u6237\u53ef\u4ee5\u4ea4\u4e92\u3002\u9000\u51fa\u65f6\u518d\u5f80\u4e0b\u8d70\uff0c\u597d\u56de\u6536\u8d44\u6e90\u3002\u6709\u65f6\u5b83\u4f1a\u505c\u5728\u534a\u5c71\u8170\u7b49\u7740\uff08\u5207\u5230\u522b\u7684 App\uff09\uff0c\u7528\u6237\u56de\u6765\u8fd8\u80fd\u56de\u5230\u5854\u5c16\uff0c\u5e76\u5c3d\u91cf\u6062\u590d\u79bb\u5f00\u65f6\u7684\u72b6\u6001\u3002<\/p>\n<\/blockquote>\n<p><!--more--><\/p>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e00\u3001\u91d1\u5b57\u5854\u6bd4\u65e7\u751f\u547d\u5468\u671f\u56fe\u66f4\u597d\u61c2<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">Figure 1\u3002\u8fd9\u5f20\u56fe\u8bb2 Activity \u751f\u547d\u5468\u671f\uff08\u91d1\u5b57\u5854\u6a21\u578b\u6bd4\u65e9\u671f Dev Guide \u91cc\u7684\u56fe\u66f4\u5f62\u8c61\uff09\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/04\/basic-lifecycle.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1393\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/04\/basic-lifecycle.png\" alt=\"basic-lifecycle\" width=\"662\" height=\"295\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u4e0d\u4e00\u5b9a\u8981\u5b9e\u73b0\u5168\u90e8\u56de\u8c03\uff0c\u4f46\u8981\u77e5\u9053\u6bcf\u4e2a\u65b9\u6cd5\u5e72\u4ec0\u4e48\uff0cApp \u624d\u80fd\u6309\u7528\u6237\u9884\u671f\u5de5\u4f5c\uff1a<\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u6765\u7535\u6216\u5207\u5230\u5176\u5b83 App \u65f6\u4e0d\u8981 crash\u3002<\/section>\n<\/li>\n<li>\n<section>\u7528\u6237\u6ca1\u5728\u7528\u67d0\u4e2a\u7ec4\u4ef6\u65f6\uff0c\u4e0d\u8981\u7a7a\u8017\u7cfb\u7edf\u8d44\u6e90\u3002<\/section>\n<\/li>\n<li>\n<section>\u79bb\u5f00\u4e00\u6bb5\u65f6\u95f4\u518d\u56de\u6765\uff0c\u4e0d\u8981\u4e22\u6389\u8fdb\u5ea6\u3002<\/section>\n<\/li>\n<li>\n<section>\u5c4f\u5e55\u65cb\u8f6c\u65f6\u4e0d\u8981 crash\uff0c\u4e5f\u4e0d\u8981\u4e22\u8fdb\u5ea6\u3002<\/section>\n<\/li>\n<\/ul>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e8c\u3001\u4e09\u4e2a\u80fd\u505c\u5f97\u4f4f\u7684\u72b6\u6001<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u56fe\u4e2d\u5404\u751f\u547d\u72b6\u6001\u91cc\uff0c\u53ea\u6709\u4e09\u4e2a\u662f<strong>\u9759\u6001<\/strong>\u7684\uff0cActivity \u53ef\u4ee5\u5728\u4e0a\u9762\u5f85\u6bd4\u8f83\u4e45\uff08\u5176\u4f59\u5f88\u5feb\u5207\u8d70\uff09\uff1a<\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section><strong>Resumed<\/strong>\uff1a\u524d\u53f0\uff0c\u7528\u6237\u53ef\u4ea4\u4e92\uff08\u5e38\u53eb running\uff09\u3002<\/section>\n<\/li>\n<li>\n<section><strong>Paused<\/strong>\uff1a\u88ab\u53e6\u4e00\u4e2a Activity \u6321\u4f4f\u2014\u2014\u540e\u8005\u5230\u4e86\u524d\u53f0\uff0c\u4f46\u662f\u534a\u900f\u660e\u3001\u6ca1\u94fa\u6ee1\u3002\u6682\u505c\u7684 Activity \u4e0d\u518d\u63a5\u6536\u8f93\u5165\uff0c\u4e5f\u4e0d\u518d\u6267\u884c\u754c\u9762\u76f8\u5173\u4ee3\u7801\uff08\u540e\u53f0\u7ebf\u7a0b\u4e0d\u4e00\u5b9a\u505c\uff09\u3002<\/section>\n<\/li>\n<li>\n<section><strong>Stopped<\/strong>\uff1a\u5b8c\u5168\u9690\u85cf\uff0c\u7528\u6237\u770b\u4e0d\u89c1\uff0c\u76f8\u5f53\u4e8e\u5728\u540e\u53f0\u3002\u5b9e\u4f8b\u548c\u72b6\u6001\u4fe1\u606f\u8fd8\u5728\uff0c\u4f46\u4e0d\u80fd\u6267\u884c\u4ee3\u7801\u3002<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\"><strong>Created<\/strong> \u4e0e <strong>Started<\/strong> \u90fd\u5f88\u77ed\uff1a\u7cfb\u7edf\u5f88\u5feb\u8dd1\u5b8c\u56de\u8c03\u5e76\u8fdb\u5165\u4e0b\u4e00\u6001\u3002\u4e5f\u5c31\u662f\u8c03\u7528 <a href=\"http:\/\/developer.android.com\/reference\/android\/app\/Activity.html#onCreate(android.os.Bundle)\">onCreate()<\/a> \u4e4b\u540e\u8fc5\u901f <a href=\"http:\/\/developer.android.com\/reference\/android\/app\/Activity.html#onStart()\">onStart()<\/a>\uff0c\u518d\u8fc5\u901f <a href=\"http:\/\/developer.android.com\/reference\/android\/app\/Activity.html#onResume()\">onResume()<\/a>\u3002\u8fd9\u5c31\u662f\u57fa\u672c\u751f\u547d\u5468\u671f\u3002<\/p>\n<table style=\"border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; text-align: left; overflow: auto; display: table; overflow-wrap: break-word; word-break: break-all;\" width=\"817\">\n<thead>\n<tr>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u72b6\u6001<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u53ef\u89c1 \/ \u53ef\u4ea4\u4e92<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u4f1a\u4e0d\u4f1a\u4e45\u505c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">Created \/ Started<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u8fc7\u6e21<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5426\uff0c\u7acb\u523b\u8fdb\u5165\u4e0b\u4e00\u56de\u8c03<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">Resumed<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u524d\u53f0\u53ef\u4ea4\u4e92<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u662f<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">Paused<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u90e8\u5206\u53ef\u89c1\uff0c\u4e0d\u63a5\u6536\u8f93\u5165<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u662f<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">Stopped<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5b8c\u5168\u4e0d\u53ef\u89c1<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u662f\uff08\u5b9e\u4f8b\u4ecd\u5728\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e09\u3001\u4e03\u4e2a\u56de\u8c03\u4e0e\u4e09\u5c42\u5d4c\u5957\u5faa\u73af<\/span><\/h2>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">void onCreate(Bundle savedInstanceState)\nvoid onStart()\nvoid onRestart()\nvoid onResume()\nvoid onPause()\nvoid onStop()\nvoid onDestroy()<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u8fd9\u4e03\u4e2a\u65b9\u6cd5\u5b9a\u4e49\u5b8c\u6574\u751f\u547d\u5468\u671f\uff0c\u4e5f\u53ef\u4ee5\u770b\u6210\u4e09\u5c42\u5d4c\u5957\u5faa\u73af\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><strong>\u5b8c\u6574\u751f\u547d\u5468\u671f<\/strong>\uff1a\u7b2c\u4e00\u6b21 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">onCreate()<\/code> \u5230 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">onDestroy()<\/code>\u3002\u5728 onCreate \u91cc\u8bbe\u5168\u5c40\u72b6\u6001\u3001\u5b8c\u6210\u521d\u59cb\u5316\uff1b\u5728 onDestroy \u91cc\u91ca\u653e\u7cfb\u7edf\u8d44\u6e90\u3002\u4f8b\u5982\u540e\u53f0\u4e0b\u8f7d\u7ebf\u7a0b\uff1aonCreate \u521b\u5efa\uff0conDestroy \u9500\u6bc1\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><strong>\u53ef\u89c6\u751f\u547d\u5468\u671f<\/strong>\uff1a<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">onStart()<\/code> \u5230 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">onStop()<\/code>\u3002\u7528\u6237\u80fd\u5728\u5c4f\u5e55\u4e0a\u770b\u5230\u5b83\uff0c\u5373\u4f7f\u4e0d\u4e00\u5b9a\u5728\u524d\u53f0\u4ea4\u4e92\u3002\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u4e4b\u95f4\u9002\u5408\u4fdd\u7559\u300c\u7ed9\u7528\u6237\u770b\u754c\u9762\u300d\u6240\u9700\u7684\u8d44\u6e90\u3002\u4f8b\u5982\u5728 onStart \u6ce8\u518c BroadcastReceiver \u76d1\u63a7\u4f1a\u5f71\u54cd UI \u7684\u53d8\u5316\uff0conStop \u91cc\u6ce8\u9500\u3002\u53ef\u89c1\u6027\u53d8\u5316\u65f6 onStart \/ onStop \u53ef\u80fd\u591a\u6b21\u8c03\u7528\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><strong>\u524d\u53f0\u751f\u547d\u5468\u671f<\/strong>\uff1a<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">onResume()<\/code> \u5230 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">onPause()<\/code>\u3002\u6b64\u65f6\u5728\u6700\u4e0a\u9762\u4e0e\u7528\u6237\u4ea4\u4e92\u3002\u4f11\u7720\u6216\u65b0 Activity \u542f\u52a8\u4f1a\u8d70 onPause\uff1b\u62ff\u5230\u7ed3\u679c\u6216\u65b0 Intent \u4f1a\u8d70 onResume\u3002\u6682\u505c\/\u6062\u590d\u4f1a\u975e\u5e38\u9891\u7e41\u3002<\/p>\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\"><strong>\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1a\u80fd\u4e45\u505c\u7684\u662f Resumed \/ Paused \/ Stopped\uff1bonCreate\u2192onDestroy \u7ba1\u5168\u5c40\u8d44\u6e90\uff0conStart\u2192onStop \u7ba1\u300c\u770b\u5f97\u89c1\u300d\uff0conResume\u2192onPause \u7ba1\u300c\u6b63\u5728\u4ea4\u4e92\u300d\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Activity \u751f\u547d\u5468\u671f\u53ef\u4ee5\u60f3\u6210\u4e00\u5ea7\u91d1\u5b57\u5854\uff1a\u7cfb\u7edf\u6309\u53f0\u9636\u8c03\u7528\u56de\u8c03\u3002\u65b0\u5efa\u5b9e\u4f8b\u65f6\u56de\u8c03\u628a\u72b6\u6001\u5f80\u4e0a\u63a8\uff1b\u5230\u5854\u5c16\u5c31\u662f\u524d\u53f0\u3001 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[195],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/535"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=535"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/535\/revisions"}],"predecessor-version":[{"id":1395,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/535\/revisions\/1395"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}