{"id":716,"date":"2023-02-26T15:23:38","date_gmt":"2023-02-26T07:23:38","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=716"},"modified":"2023-04-29T17:16:00","modified_gmt":"2023-04-29T09:16:00","slug":"exploration-of-android-exit-application-program","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/exploration-of-android-exit-application-program\/","title":{"rendered":"Android\u9000\u51fa\u5e94\u7528\u7a0b\u5e8f\u63a2\u8ba8"},"content":{"rendered":"<h2>\u9000\u51fa\u65b9\u5f0f<\/h2>\n<p>Android\u9000\u51fa\u7a0b\u5e8f\u7684\u4e24\u79cd\u65b9\u5f0f\uff1a<code>killProcess()<\/code>\u548c<code>System.exit()<\/code><\/p>\n<p><!-- more --><\/p>\n<h3>killProcess()<\/h3>\n<p>\u8c03\u7528<\/p>\n<pre><code class=\"language-java\">android.os.Process.killProcess(android.os.Process.myPid())<\/code><\/pre>\n<p>\u53ef\u4ee5\u6740\u6b7b\u5f53\u524d\u5e94\u7528\u6d3b\u52a8\u7684\u8fdb\u7a0b\uff0c\u8fd9\u4e00\u64cd\u4f5c\u5c06\u4f1a\u628a\u6240\u6709\u8be5\u8fdb\u7a0b\u5185\u7684\u8d44\u6e90\uff08\u5305\u62ec\u7ebf\u7a0b\u5168\u90e8\u6e05\u7406\u6389\uff09\u3002\u5f53\u7136\uff0c\u7531\u4e8eActivityManager\u65f6\u523b\u76d1\u542c\u7740\u8fdb\u7a0b\uff0c\u4e00\u65e6\u53d1\u73b0\u8fdb\u7a0b\u88ab\u975e\u6b63\u5e38Kill\uff0c\u5b83\u5c06\u4f1a\u8bd5\u56fe\u53bb\u91cd\u542f\u8fd9\u4e2a\u8fdb\u7a0b\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\uff0c\u6709\u65f6\u5019\u5f53\u6211\u4eec\u8bd5\u56fe\u8fd9\u6837\u53bb\u7ed3\u675f\u6389\u5e94\u7528\u65f6\uff0c\u53d1\u73b0\u5b83\u53c8\u81ea\u52a8\u91cd\u65b0\u542f\u52a8\u7684\u539f\u56e0\uff0c\u4e0b\u6587\u5c06\u4f1a\u964d\u5230\u5e94\u7528\u81ea\u6740\u91cd\u542f\u7684\u6761\u4ef6\u3002<\/p>\n<h3>System.exit()<\/h3>\n<p><code>System.exit()<\/code>\u5176\u5b9e\u662fJava\u4e2d\u7ed3\u675f\u8fdb\u7a0b\u7684\u65b9\u6cd5\uff0c\u8c03\u7528\u5b83\u5c06\u5173\u95ed\u5f53\u524d\u7684JVM\u865a\u62df\u673a\u3002<\/p>\n<p><code>System.exit(0)<\/code>\u548c<code>System.exit(1)<\/code>\u7684\u533a\u522b\uff1a<\/p>\n<ul>\n<li><code>System.exit(0)<\/code>\u8868\u793a\u662f\u6b63\u5e38\u9000\u51fa<\/li>\n<li><code>System.exit(1)<\/code>\u8868\u793a\u662f\u975e\u6b63\u5e38\u9000\u51fa\uff0c\u901a\u5e38\u8fd9\u79cd\u9000\u51fa\u65b9\u5f0f\u5e94\u8be5\u653e\u5728catch\u5757\u4e2d<\/li>\n<\/ul>\n<h2>APP\u81ea\u6740\u91cd\u542f<\/h2>\n<p>\u65e0\u8bba\u662f<code>killProcess()<\/code>\u65b9\u5f0f\uff0c\u8fd8\u662f<code>System.exit()<\/code>\u65b9\u5f0f\uff0c\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u6740\u6b7b\u5e94\u7528\u5747\u4f1a\u5c1d\u8bd5\u91cd\u542f\u5e94\u7528\uff0c\u5728\u5b50\u7ebf\u7a0b\u4e2d\u6740\u6b7b\u5e94\u7528\u5219\u4e0d\u4f1a\u91cd\u542f\u5e94\u7528\u3002<\/p>\n<h3>\u4e3bUI\u7ebf\u7a0b\u6267\u884c<\/h3>\n<pre><code class=\"language-java\">@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.activity_main);\n    \/\/android.os.Process.killProcess(android.os.Process.myPid());\n    System.exit(0);\n}<\/code><\/pre>\n<p>\u53ef\u89c1APP\u4e0d\u65ad\u81ea\u6740\u91cd\u542f\uff0c\u8fdb\u7a0b\u53f7\u4e5f\u5728\u6539\u53d8<\/p>\n<pre><code>04-17 16:15:06.087 1115-1115\/cn.appblog.killapp I\/yezhou: AppApplication.onCreate\n04-17 16:15:06.943 1424-1424\/cn.appblog.killapp I\/yezhou: AppApplication.onCreate\n04-17 16:15:07.772 1677-1677\/cn.appblog.killapp I\/yezhou: AppApplication.onCreate\n04-17 16:15:08.628 1952-1952\/cn.appblog.killapp I\/yezhou: AppApplication.onCreate\n04-17 16:15:09.431 2167-2167\/cn.appblog.killapp I\/yezhou: AppApplication.onCreate\n04-17 16:15:10.245 2357-2357\/cn.appblog.killapp I\/yezhou: AppApplication.onCreate\n04-17 16:15:11.052 2566-2566\/cn.appblog.killapp I\/yezhou: AppApplication.onCreate\n04-17 16:15:12.044 2758-2758\/cn.appblog.killapp I\/yezhou: AppApplication.onCreate\n04-17 16:15:12.845 2960-2960\/cn.appblog.killapp I\/yezhou: AppApplication.onCreate\n04-17 16:15:13.844 3148-3148\/cn.appblog.killapp I\/yezhou: AppApplication.onCreate\n04-17 16:15:14.681 3316-3316\/cn.appblog.killapp I\/yezhou: AppApplication.onCreate<\/code><\/pre>\n<h3>\u5b50\u7ebf\u7a0b\u6267\u884c<\/h3>\n<pre><code class=\"language-java\">@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.activity_main);\n    new Handler().postDelayed(new Runnable() {\n        @Override\n        public void run() {\n            \/\/android.os.Process.killProcess(android.os.Process.myPid());\n            System.exit(0);\n        }\n    }, 2000);\n}<\/code><\/pre>\n<p>\u53ef\u89c1APP\u4e0d\u518d\u542f\u52a8<\/p>\n<pre><code>04-17 16:17:16.398 5087-5087\/com.lianlianpay.webview I\/yezhou: AppApplication.onCreate<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9000\u51fa\u65b9\u5f0f Android\u9000\u51fa\u7a0b\u5e8f\u7684\u4e24\u79cd\u65b9\u5f0f\uff1akillProcess()\u548cSystem.exit() killP [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-716","post","type-post","status-publish","format-standard","hentry","category-android-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/716","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=716"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/716\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}