{"id":494,"date":"2012-12-16T15:38:42","date_gmt":"2012-12-16T07:38:42","guid":{"rendered":"http:\/\/guoh.ai\/lifelog\/?p=494"},"modified":"2012-12-16T15:38:42","modified_gmt":"2012-12-16T07:38:42","slug":"build-up-high-responsiveness-android-app","status":"publish","type":"post","link":"https:\/\/guoh.ai\/lifelog\/2012\/12\/build-up-high-responsiveness-android-app\/","title":{"rendered":"\u5f00\u53d1\u9ad8\u54cd\u5e94\u7684Android\u5e94\u7528"},"content":{"rendered":"<p>\u7f51\u7edc\u4e0a\u4ece\u6765\u6ca1\u6709\u95f4\u65ad\u8fc7\u5bf9Android\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u6162\u7684\u8d28\u7591\uff0c\u786c\u4ef6\u914d\u7f6e\u9ad8\uff0c\u4f46\u7528\u8d77\u6765\u5c31\u662f\u4e0d\u987a\uff0c\u987f\u5361\uff0c\u7b49\u7b49\u5404\u79cd\u73b0\u8c61\u3002<br \/>\nhttps:\/\/plus.google.com\/100838276097451809262\/posts\/VDkV9XaJRGS<br \/>\nhttp:\/\/mobile.163.com\/12\/1123\/05\/8GVKOL7D0011309K_all.html<br \/>\nhttp:\/\/www.evolife.cn\/html\/2011\/62866.html<br \/>\n\u53ef\u4ee5\u53c2\u9605\u4ee5\u4e0a\u4e00\u4e9b\u6587\u7ae0<\/p>\n<p>\u9664\u4e86Android\u7684framework\u672c\u8eab\u7684\u8bbe\u8ba1\u56e0\u7d20\u5916\uff0c\u90a3\u8fd8\u6709\u54ea\u4e9b\u5730\u65b9\u503c\u5f97\u6211\u4eec\u6ce8\u610f\u7684\u5462\uff1f<br \/>\n1\u3001\u63a7\u5236\u597dAPP\u7684thread\uff0cUI\u54cd\u5e94\u7684\u4e8b\u60c5\u653e\u5230UI thread(\u4e5f\u5c31\u662f\u9ed8\u8ba4\u7684main thread)\uff0c\u5176\u4ed6\u6bd4\u8f83\u8017\u65f6\u6216\u8005<br \/>\n\u8ddfUI\u4e0d\u7d27\u5bc6\u7684\u64cd\u4f5c\u653e\u5230worker thread(\u8fd9\u4e2a\u9700\u8981\u5f00\u53d1\u8005\u81ea\u5df1\u8bbe\u8ba1\u5b9e\u73b0\u7684\u4e00\u4e2athread\uff0c\u591a\u534a\u662f\u6267\u884c\u548cUI\u6ca1\u6709<br \/>\n\u4ec0\u4e48\u5173\u7cfb\u7684\u64cd\u4f5c\uff0c\u5e76\u6700\u7ec8\u628a\u9700\u8981\u663e\u793a\u7684\u6570\u636epost\u56de\u7ed9UI thread)\uff0c\u4e00\u822c\u5b83\u9700\u8981\u5feb\u901f\u54cd\u5e94\u6765\u81eaUI thread\u7684\u4e8b<br \/>\n\u4ef6\u8bf7\u6c42\uff0c\u6bd4\u5982\u6dfb\u52a0\u4e00\u4e2aaction(action\u5c31\u662fUI thread\u63a5\u6536\u5230\u7528\u6237\u7684\u4e8b\u4ef6\u4e4b\u540e\u9700\u8981\u505a\u7684\u52a8\u4f5c)\u8fdb\u6765\uff0c\u5220\u9664\u67d0\u4e2a<br \/>\naction\uff0c\u8c03\u6574action\u7684\u4f18\u5148\u7ea7\u3002<\/p>\n<p>2\u3001\u4e0d\u8981\u8ba9APP\u7684thread\u7206\u6389\uff0cJava\u8bed\u8a00\u5f53\u4e2dthread\u7684\u4f7f\u7528\u5f88\u662f\u7b80\u5355\u548c\u65b9\u4fbf\uff0c\u6b63\u662f\u56e0\u4e3a\u597d\u7528\u6240\u4ee5\u4e0d\u8981\u6ee5\u7528\u3002<\/p>\n<p>3\u3001\u7528\u6237\u79bb\u5f00APP\u7684\u65f6\u5019\uff0c\u4e0d\u9700\u8981\u518d\u6267\u884c\u7684\u64cd\u4f5c\u5c31\u4e0d\u5fc5\u8981\u518d\u6267\u884c\u4e86\u3002\u56e0\u4e3aAndroid kernal\u652f\u6301\u5b8c\u5168\u7684\u591a\u8fdb\u7a0b\uff0c<br \/>\n\u6240\u4ee5\u7528\u6237\u79bb\u5f00\u4e86\u53ef\u80fd\u4e00\u4e9b\u64cd\u4f5c\u8fd8\u662f\u4f1a\u5360\u7528CPU\u5728\u6267\u884c\uff0c\u8fd9\u662f\u5e94\u5f53\u907f\u514d\u7684\u3002\u867d\u7136\u4f1a\u589e\u52a0\u7a0b\u5e8f\u5f00\u53d1\u7684\u590d\u6742\u5ea6\uff0c\u4f46\u662f\u8c01\u8ba9<br \/>\n\u4f60\u505aAndroid\u5f00\u53d1\u5462\uff1f<\/p>\n<p>4\u3001\u9002\u5f53\u964d\u4f4eworker thread\u7684\u4f18\u5148\u7ea7\uff0c\u8fd9\u70b9\u5f88\u5bb9\u6613\u88ab\u4eba\u5ffd\u89c6\uff0c\u9ed8\u8ba4\u521b\u5efa\u51fa\u6765\u7684thread\u7684\u4f18\u5148\u7ea7\u548c<br \/>\nmain thread\u662f\u4e00\u6837\uff0c\u5982\u679c\u4e0d\u964d\u4f4e\u5b83\u4e5f\u4f1a\u8ddfmain thread\u62a2CPU<\/p>\n<p>5\u3001\u53cb\u597d\u7684loading\u63d0\u793a\uff0c\u8fd9\u4e00\u62db\u662f\u5fc3\u7406\u6218\uff0c\u4f46\u662f\u4e5f\u7ba1\u7528\u3002<\/p>\n<p>\u5f53\u7136\u8fd8\u6709\u4f60\u7684\u7a0b\u5e8f\u8981\u5199\u7684\u9ad8\u6548\u7387\u5566\uff0c\u73b0\u5728\u5f88\u591a\u4eba\u90fd\u80fd\u62b1\u7740\u80fd\u8fd0\u884c\u5c31\u597d\u7684\u5fc3\u6001\uff0cbug\u80fd\u4e0d\u89e3\u5c31\u4e0d\u89e3\u7684\u5fc3\u6001\uff0c<br \/>\n\u8fd9\u6837\u600e\u4e48\u53ef\u80fd\u51fa\u9ad8\u8d28\u91cf\u7684APP\u7684\u5462\uff1f\u9ad8\u54c1\u8d28\u7684\u4e1c\u897f\u662f\u7ec6\u7ec6\u6253\u78e8\u51fa\u6765\u7684\u3002<\/p>\n<p>PS. \u4ee5\u4e0b\u4e00\u4e9b\u547d\u4ee4\u6216\u8005\u5de5\u5177\u53ef\u80fd\u662f\u6709\u5e2e\u52a9\u7684<br \/>\n$ adb shell top -m MAX_PROCESS_COUNT<br \/>\n$ adb shell top -m MAX_THREAD_COUNT -t<\/p>\n<p>\u4f8b\u5982<br \/>\n$ adb shell top -m 20<\/p>\n<p>Systrace\u53c2\u89c1<br \/>\nhttp:\/\/developer.android.com\/tools\/help\/systrace.html<\/p>\n<p>Traceview\u53c2\u89c1<br \/>\nhttp:\/\/developer.android.com\/tools\/help\/traceview.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7f51\u7edc\u4e0a\u4ece\u6765\u6ca1\u6709\u95f4\u65ad\u8fc7\u5bf9Android\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u6162\u7684\u8d28\u7591\uff0c\u786c\u4ef6\u914d\u7f6e\u9ad8\uff0c\u4f46\u7528\u8d77\u6765\u5c31\u662f\u4e0d\u987a\uff0c\u987f\u5361\uff0c\u7b49\u7b49\u5404\u79cd\u73b0\u8c61\u3002 https:\/\/plus.google.com\/100838276097451809262\/posts\/VDkV9XaJRGS http:\/\/mobile.163.com\/12\/1123\/05\/8GVKOL7D0011309K_all.html http:\/\/www.evolife.cn\/html\/2011\/62866.html \u53ef\u4ee5\u53c2\u9605\u4ee5\u4e0a\u4e00\u4e9b\u6587\u7ae0 \u9664\u4e86Android\u7684framework\u672c\u8eab\u7684\u8bbe\u8ba1\u56e0\u7d20\u5916\uff0c\u90a3\u8fd8\u6709\u54ea\u4e9b\u5730\u65b9\u503c\u5f97\u6211\u4eec\u6ce8\u610f\u7684\u5462\uff1f 1\u3001\u63a7\u5236\u597dAPP\u7684thread\uff0cUI\u54cd\u5e94\u7684\u4e8b\u60c5\u653e\u5230UI thread(\u4e5f\u5c31\u662f\u9ed8\u8ba4\u7684main thread)\uff0c\u5176\u4ed6\u6bd4\u8f83\u8017\u65f6\u6216\u8005 \u8ddfUI\u4e0d\u7d27\u5bc6\u7684\u64cd\u4f5c\u653e\u5230worker thread(\u8fd9\u4e2a\u9700\u8981\u5f00\u53d1\u8005\u81ea\u5df1\u8bbe\u8ba1\u5b9e\u73b0\u7684\u4e00\u4e2athread\uff0c\u591a\u534a\u662f\u6267\u884c\u548cUI\u6ca1\u6709 \u4ec0\u4e48\u5173\u7cfb\u7684\u64cd\u4f5c\uff0c\u5e76\u6700\u7ec8\u628a\u9700\u8981\u663e\u793a\u7684\u6570\u636epost\u56de\u7ed9UI thread)\uff0c\u4e00\u822c\u5b83\u9700\u8981\u5feb\u901f\u54cd\u5e94\u6765\u81eaUI thread\u7684\u4e8b \u4ef6\u8bf7\u6c42\uff0c\u6bd4\u5982\u6dfb\u52a0\u4e00\u4e2aaction(action\u5c31\u662fUI thread\u63a5\u6536\u5230\u7528\u6237\u7684\u4e8b\u4ef6\u4e4b\u540e\u9700\u8981\u505a\u7684\u52a8\u4f5c)\u8fdb\u6765\uff0c\u5220\u9664\u67d0\u4e2a action\uff0c\u8c03\u6574action\u7684\u4f18\u5148\u7ea7\u3002 2\u3001\u4e0d\u8981\u8ba9APP\u7684thread\u7206\u6389\uff0cJava\u8bed\u8a00\u5f53\u4e2dthread\u7684\u4f7f\u7528\u5f88\u662f\u7b80\u5355\u548c\u65b9\u4fbf\uff0c\u6b63\u662f\u56e0\u4e3a\u597d\u7528\u6240\u4ee5\u4e0d\u8981\u6ee5\u7528\u3002 3\u3001\u7528\u6237\u79bb\u5f00APP\u7684\u65f6\u5019\uff0c\u4e0d\u9700\u8981\u518d\u6267\u884c\u7684\u64cd\u4f5c\u5c31\u4e0d\u5fc5\u8981\u518d\u6267\u884c\u4e86\u3002\u56e0\u4e3aAndroid kernal\u652f\u6301\u5b8c\u5168\u7684\u591a\u8fdb\u7a0b\uff0c \u6240\u4ee5\u7528\u6237\u79bb\u5f00\u4e86\u53ef\u80fd\u4e00\u4e9b\u64cd\u4f5c\u8fd8\u662f\u4f1a\u5360\u7528CPU\u5728\u6267\u884c\uff0c\u8fd9\u662f\u5e94\u5f53\u907f\u514d\u7684\u3002\u867d\u7136\u4f1a\u589e\u52a0\u7a0b\u5e8f\u5f00\u53d1\u7684\u590d\u6742\u5ea6\uff0c\u4f46\u662f\u8c01\u8ba9 \u4f60\u505aAndroid\u5f00\u53d1\u5462\uff1f 4\u3001\u9002\u5f53\u964d\u4f4eworker thread\u7684\u4f18\u5148\u7ea7\uff0c\u8fd9\u70b9\u5f88\u5bb9\u6613\u88ab\u4eba\u5ffd\u89c6\uff0c\u9ed8\u8ba4\u521b\u5efa\u51fa\u6765\u7684thread\u7684\u4f18\u5148\u7ea7\u548c main thread\u662f\u4e00\u6837\uff0c\u5982\u679c\u4e0d\u964d\u4f4e\u5b83\u4e5f\u4f1a\u8ddfmain thread\u62a2CPU 5\u3001\u53cb\u597d\u7684loading\u63d0\u793a\uff0c\u8fd9\u4e00\u62db\u662f\u5fc3\u7406\u6218\uff0c\u4f46\u662f\u4e5f\u7ba1\u7528\u3002 \u5f53\u7136\u8fd8\u6709\u4f60\u7684\u7a0b\u5e8f\u8981\u5199\u7684\u9ad8\u6548\u7387\u5566\uff0c\u73b0\u5728\u5f88\u591a\u4eba\u90fd\u80fd\u62b1\u7740\u80fd\u8fd0\u884c\u5c31\u597d\u7684\u5fc3\u6001\uff0cbug\u80fd\u4e0d\u89e3\u5c31\u4e0d\u89e3\u7684\u5fc3\u6001\uff0c \u8fd9\u6837\u600e\u4e48\u53ef\u80fd\u51fa\u9ad8\u8d28\u91cf\u7684APP\u7684\u5462\uff1f\u9ad8\u54c1\u8d28\u7684\u4e1c\u897f\u662f\u7ec6\u7ec6\u6253\u78e8\u51fa\u6765\u7684\u3002 PS. \u4ee5\u4e0b\u4e00\u4e9b\u547d\u4ee4\u6216\u8005\u5de5\u5177\u53ef\u80fd\u662f\u6709\u5e2e\u52a9\u7684 $ adb shell top -m MAX_PROCESS_COUNT $ adb shell top -m MAX_THREAD_COUNT -t \u4f8b\u5982 $ adb shell top -m 20 Systrace\u53c2\u89c1 http:\/\/developer.android.com\/tools\/help\/systrace.html Traceview\u53c2\u89c1 &hellip; <a href=\"https:\/\/guoh.ai\/lifelog\/2012\/12\/build-up-high-responsiveness-android-app\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u5f00\u53d1\u9ad8\u54cd\u5e94\u7684Android\u5e94\u7528<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_gfmr_meta_descriptions":[],"_gfmr_multilingual_taxonomy_terms":[],"footnotes":""},"categories":[7],"tags":[],"class_list":["post-494","post","type-post","status-publish","format-standard","hentry","category-android"],"_links":{"self":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/comments?post=494"}],"version-history":[{"count":2,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/494\/revisions"}],"predecessor-version":[{"id":496,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/494\/revisions\/496"}],"wp:attachment":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/media?parent=494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/categories?post=494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/tags?post=494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}