{"id":1278,"date":"2018-01-30T14:44:58","date_gmt":"2018-01-30T06:44:58","guid":{"rendered":"http:\/\/blog.xiunian.wang\/?p=1278"},"modified":"2023-06-25T23:59:59","modified_gmt":"2023-06-25T15:59:59","slug":"android-%e4%b8%ad%e7%9a%84%e5%86%85%e5%ad%98%e6%b3%84%e6%bc%8f","status":"publish","type":"post","link":"https:\/\/blog.xiunian.wang\/?p=1278","title":{"rendered":"Android \u4e2d\u7684\u5185\u5b58\u6cc4\u6f0f"},"content":{"rendered":"\n<p>JVM\u5783\u573e\u56de\u6536\u673a\u5236 \u4f1a\u5bf9\u6ca1\u6709\u5f15\u7528\u7684\u5bf9\u8c61\u8fdb\u884c\u56de\u6536\uff0c\u800c\u6301\u6709\u5f15\u7528\u7684\u5bf9\u8c61\u662f\u4e0d\u80fd\u88ab\u56de\u6536\u7684\u3002<\/p>\n\n\n\n<p>\u533f\u540d\u5185\u90e8\u7c7b\u5305\u542b\u5982\u4e0b\u7279\u5f81<br>1. new \u64cd\u4f5c\u7b26<br>2. \u5b9e\u73b0\u4e00\u4e2a\u63a5\u53e3\uff0c\u6216\u8005\u7ee7\u627f\u81ea\u4e00\u4e2a\u7c7b<br>3. \u6709\u6784\u9020\u51fd\u6570\u7684\u8c03\u7528\uff0c\u63a5\u53e3\u56e0\u4e3a\u6ca1\u6709\u6784\u9020\u51fd\u6570\uff0c\u9ed8\u8ba4\u662f\u65e0\u53c2\u6784\u9020\u51fd\u6570\u3002<br>4. \u62e5\u6709body\uff0c\u5c31\u50cf\u7c7b\u5b9a\u4e49\u4e00\u6837\uff0cbody\u5185\u53ef\u4ee5\u58f0\u660e\u65b9\u6cd5\uff0c\u4f46\u662f \u4e0d\u80fd\u62d3\u5c55\u6784\u9020\u51fd\u6570\u3002<\/p>\n\n\n\n<p>\u533f\u540d\u5185\u90e8\u5185\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u672c\u5730\u7c7b\u7684\u6210\u5458\u53d8\u91cf\u3002\u53ef\u8bbf\u95ee \u65b9\u6cd5\u5185\u901a\u8fc7final \u4fee\u9970\u7684\u672c\u5730\u53d8\u91cf\u3002<br>\u56e0\u6b64\u5e38\u89c1\u7684\u6cc4\u6f0f\u5c31\u662f<a rel=\"noreferrer noopener\" href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/javaOO\/anonymousclasses.html\" target=\"_blank\">\u533f\u540d\u5185\u90e8\u7c7b<\/a>\u5b58\u5728\u5bf9act\u7684\u5f15\u7528\u3002<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">  private Object obj=new Object(){\n        @Override\n        public String toString() {\n            return super.toString()+\"bbb\";\n        }\n    };<\/pre>\n\n\n\n<!--more-->\n\n\n\n<p>\u7136\u540e\u628aobj \u8d4b\u503c\u7ed9\u67d0\u9759\u6001\u53d8\u91cf\uff0c\u6b64\u65f6 \u5185\u5b58\u6cc4\u6f0f\u53c8\u51fa\u6765\u4e86\u3002 \u56e0\u6b64\u533f\u540d\u5185\u90e8\u7c7b\u4f1a\u6301\u6709\u6240\u5728\u7c7b\u7684\u5f15\u7528<\/p>\n\n\n\n<p>XXXActivity@1 \u8fd9\u6837\u5b50\u7684\u5c31\u662f\u533f\u540d\u5185\u90e8\u7c7b\u3002<\/p>\n\n\n\n<p>Java \u548c Kotlin\u4e2d\u7684Handler \u9020\u6210\u7684\u6cc4\u6f0f\u51fa\u73b0\u4e0d\u4e00\u6837\u7684\u7ed3\u679c\uff0c<\/p>\n\n\n\n<p>\u6211\u5728java\u4e2d\u662f\u8fd9\u4e48\u5199\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\"> new Handler().postDelayed(new Runnable() {\n            @Override public void run() {\n                Log.d(\"TAG\",\"testtest\");\n            }\n        }, 60000);<\/pre>\n\n\n\n<p>Kotlin \u4e2d\u7528lambda\u8868\u8fbe\u5f0f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Handler().postDelayed({ Log.d(\"TAG\", \"testtest\") }, 60000)<\/code><\/pre>\n\n\n\n<p>\u5b9e\u6d4b java\u7248\u672c\u7684\u4ee3\u7801\u4f1a\u9020\u6210\u5185\u5b58\u6cc4\u6f0f\uff0c\u800ckotlin\u7248\u672c\u5c31\u4e0d\u4f1a\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\uff1f<br>messageQueue\u4e2d\u6709\u5f15\u7528Runnable,\u800crunnable \u6301\u6709Act \u7684\u5f15\u7528\uff0c\u6240\u4ee5\u4f1a\u6709\u5185\u5b58\u6cc4\u6f0f\uff0c\u800ckotlin \u5728\u7f16\u8bd1\u7684\u65f6\u5019\u5e76\u6ca1\u6709\u5728\u4ee3\u7801\u4e2d\u751f\u6210\u4e00\u4e2a\u533f\u540d\u5185\u90e8\u7c7b\uff0c\u53ea\u662f\u4e00\u4e2arunnable\u3002\u6ca1\u6709\u5b58\u5728\u5bf9act\u7684\u5f15\u7528\uff0c\u4f46\u662f\uff0c\u5982\u679c\u5728\u4ee3\u7801\u4e2d\u7528\u5230\u4e86activity\u7684\u6210\u5458\u53d8\u91cf\uff0c\u4e5f\u4f1a\u9020\u6210\u5f15\u7528\uff0c\uff08\u4e3a\u4ec0\u4e48\uff1f \uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JVM\u5783\u573e\u56de\u6536\u673a\u5236 \u4f1a\u5bf9\u6ca1\u6709\u5f15\u7528\u7684\u5bf9\u8c61\u8fdb\u884c\u56de\u6536\uff0c\u800c\u6301\u6709\u5f15\u7528\u7684\u5bf9\u8c61\u662f\u4e0d\u80fd\u88ab\u56de\u6536\u7684\u3002 \u533f\u540d\u5185\u90e8\u7c7b\u5305\u542b\u5982\u4e0b\u7279\u5f811. new \u64cd\u4f5c\u7b262. \u5b9e\u73b0\u4e00\u4e2a\u63a5\u53e3\uff0c\u6216\u8005\u7ee7\u627f\u81ea\u4e00\u4e2a\u7c7b3. \u6709\u6784\u9020\u51fd\u6570\u7684\u8c03\u7528\uff0c\u63a5\u53e3\u56e0\u4e3a\u6ca1\u6709\u6784\u9020\u51fd\u6570\uff0c\u9ed8\u8ba4\u662f\u65e0\u53c2\u6784\u9020\u51fd\u6570\u30024. \u62e5\u6709body\uff0c\u5c31\u50cf\u7c7b\u5b9a\u4e49\u4e00\u6837\uff0cbody\u5185\u53ef\u4ee5\u58f0\u660e\u65b9\u6cd5\uff0c\u4f46\u662f \u4e0d\u80fd\u62d3\u5c55\u6784\u9020\u51fd\u6570\u3002 \u533f\u540d\u5185\u90e8\u5185\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u672c\u5730\u7c7b\u7684\u6210\u5458\u53d8\u91cf\u3002\u53ef\u8bbf\u95ee \u65b9\u6cd5\u5185\u901a\u8fc7final \u4fee\u9970\u7684\u672c\u5730\u53d8\u91cf\u3002\u56e0\u6b64\u5e38\u89c1\u7684\u6cc4\u6f0f\u5c31\u662f\u533f\u540d\u5185\u90e8\u7c7b\u5b58\u5728\u5bf9act\u7684\u5f15\u7528\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,8],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts\/1278"}],"collection":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1278"}],"version-history":[{"count":10,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts\/1278\/revisions"}],"predecessor-version":[{"id":1739,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts\/1278\/revisions\/1739"}],"wp:attachment":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}