
{"id":963,"date":"2017-01-19T12:22:18","date_gmt":"2017-01-19T04:22:18","guid":{"rendered":"http:\/\/www.jiandaima.com\/blog\/?p=963"},"modified":"2017-01-19T12:22:18","modified_gmt":"2017-01-19T04:22:18","slug":"6-%e4%b8%aa%e5%8f%af%e4%bb%a5%e8%ae%a9%e4%bb%a3%e7%a0%81%e5%8f%98%e5%be%97%e6%9b%b4%e6%95%b4%e6%b4%81%e7%9a%84-android-%e5%ba%93","status":"publish","type":"post","link":"http:\/\/www.jiandaima.com\/blog\/archives\/963.html","title":{"rendered":"6 \u4e2a\u53ef\u4ee5\u8ba9\u4ee3\u7801\u53d8\u5f97\u66f4\u6574\u6d01\u7684 Android \u5e93"},"content":{"rendered":"<p>Android\u5f00\u53d1\u662f\u6709\u8da3\u7684\u2014\u2014\u8fd9\u6beb\u65e0\u7591\u95ee\u3002\u7136\u800c\uff0c\u8fd8\u662f\u6709\u5f88\u591a\u5e73\u53f0\u8feb\u4f7f\u6211\u4eec\u7f16\u5199\u91cd\u590d\u7684\u6837\u677f\u4ee3\u7801\u3002\u5f88\u591a\u65f6\u5019\u8fd9\u90fd\u4e0e\u9700\u8981\u4f60\u5904\u7406\u7684UI\u7ec4\u4ef6\u76f8\u5173\u3002\u6709\u4e00\u4e9b\u786e\u5b9e\u662f\u4f60\u9700\u8981\u7684\uff0c\u5f53\u4f60\u5e0c\u671b\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u67b6\u6784\u80fd\u591f\u5e72\u5e72\u51c0\u51c0\u7684\u65f6\u5019\u3002\u6709\u5f88\u591a\u64cd\u4f5c\u5728\u540e\u53f0\u5f02\u6b65\u6267\u884c\uff1b\u4e8b\u5b9e\u4e0a\uff0c\u6700\u540e\u5f88\u5bb9\u6613\u6210\u4e3a\u4e00\u5806\u610f\u5927\u5229\u9762\u6761\u4f3c\u7684\u4ee3\u7801\uff0c\u4e0d\u53ef\u8bfb\u6216\u8005\u5c31\u662f\u8ba9\u4eba\u611f\u89c9\u4e0d\u6b63\u786e\u3002<\/p>\n<p>\u4eca\u5929\uff0c\u6211\u4eec\u5c06\u770b\u770b6\u4e2a\u53ef\u4ee5\u5e2e\u52a9\u4fdd\u6301\u4ee3\u7801\u6e05\u6670\u548c\u53ef\u8bfb\u6027\u7684Android\u5e93\uff0c\u5e76\u4e14\u4f7f\u7528\u793a\u4f8b\u9879\u76ee\u4ee5\u65b9\u4fbf\u4f60\u53ef\u4ee5\u770b\u5230\u5e93\u7684\u4f5c\u7528\u3002<\/p>\n<p><em>\u9879\u76ee<\/em><\/p>\n<p>\u6211\u4eec\u5c06\u4f7f\u7528\u4e4b\u524d\u6211\u4eec\u5728Retrofit\u6307\u5357\u4e2d\u4f7f\u7528\u8fc7\u7684Retrofit 2 Sample\u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5f00\u6e90\u9879\u76ee\uff0c\u53ef\u4ee5\u5728GitHub\u4e0a\u627e\u5230\u3002\u5b83\u9700\u8981\u4e00\u4e2a\u516c\u53f8\u540d\u79f0\u548c\u4e00\u4e2aGit\u5b58\u50a8\u4ed3\u5e93\uff0c\u5e76\u5217\u51fa\u6240\u6709\u7684\u8d21\u732e\u8005\uff0c\u8d21\u732e\u8005\u663e\u793a\u4e3a\u5e26\u6709\u5934\u50cf\u7684\u4e00\u4e2a\u5217\u8868\u3002\u867d\u7136\u5b83\u4e0d\u662f\u4e00\u4e2a\u9769\u547d\u6027\u7684app\uff0c\u4f46\u662f\u5b83\u5c55\u793a\u4e86\u5982\u4f55\u6267\u884c\u7f51\u7edc\uff0c\u4f7f\u7528\u56fe\u50cf\uff0c\u521b\u5efa\u5217\u8868\u7ec4\u4ef6\uff0c\u4ee5\u53ca\u5904\u7406\u7528\u6237\u8f93\u5165\u3002\u4f60\u53ef\u4ee5\u968f\u610f\u6446\u5f04\u8fd9\u4e2a\u529f\u80fd\u9f50\u5168\u7684\u73a9\u5177\u9879\u76ee\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u5c06\u6ce8\u91ca\u5e93\u5e94\u7528\u5230\u4ee3\u7801\uff0c\u6765\u770b\u770b\u5b83\u4eec\u5982\u4f55\u5e2e\u52a9\u7ef4\u62a4Android app\u4ee3\u7801\u7684\u6574\u6d01\u3002<br \/>\n<em><br \/>\n1.Butter Knife<\/em><\/p>\n<p>\u6bcf\u5f53\u4f60\u9700\u8981\u8bbf\u95ee\u4ee3\u7801\u4e2d\u7684\u89c6\u56fe\u65f6\uff0c\u4f60\u9700\u8981\u83b7\u53d6\u8be5\u89c6\u56fe\u7684\u5bf9\u8c61\u5b9e\u4f8b\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199rootView.findViewById()\u65b9\u6cd5\u6765\u5b9e\u73b0\uff0c\u7136\u540e\u5c06\u8fd4\u56de\u7684\u5bf9\u8c61\u8f6c\u6362\u4e3a\u6b63\u786e\u7684\u89c6\u56fe\u7c7b\u578b\u3002\u4f46\u662f\uff0c\u4f60\u7684\u4ee3\u7801\u5f88\u5feb\u5c31\u4f1a\u5efa\u7acb\u8d77\u6765\uff0c\u4f46\u662f\u5c24\u5176\u662f\u5728onCreate\u548conCreateView\u65b9\u6cd5\u4e2d\u4f1a\u6709\u607c\u4eba\u7684\u7c7b\u4f3c\u8bed\u53e5\u3002\u60f3\u60f3\u770b\uff1b\u5728\u90a3\u4e9bonCreate\u65b9\u6cd5\u4e2d\uff0c\u4f60\u521d\u59cb\u5316\u4e00\u5207\uff0c\u7ed1\u5b9a\u4fa6\u542c\u5668\uff0c\u628a\u6574\u4e2aUI\u7ed1\u5728\u4e00\u8d77\u3002\u4f60\u62e5\u6709\u7684UI\u5143\u7d20\u8d8a\u591a\uff0c\u90a3\u4e48\u5355\u4e2a\u65b9\u6cd5\u5c31\u4f1a\u8d8a\u957f\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u4e3e\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<p><a href=\"https:\/\/www.jiandaima.com\/blog\/wp-content\/uploads\/2017\/01\/14845393411.png\" class=\"highslide-image\" onclick=\"return hs.expand(this);\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/images.jiandaima.com\/blog\/wp-content\/uploads\/2017\/01\/14845393411-163x300.png\" alt=\"\" width=\"163\" height=\"300\" class=\"aligncenter size-medium wp-image-965\" \/><\/a><\/p>\n<p>\u6b64\u89c6\u56fe\u5c06\u9700\u8981\u4e09\u4e2a\u89c6\u56fe\uff1a\u4e24\u4e2aEditTexts\u548c\u4e00\u4e2aButton\uff0c\u6211\u4eec\u9700\u8981\u5728\u7247\u6bb5\u4e2d\u5f15\u7528\u3002\u4e00\u822c\u6211\u4eec\u4f1a\u8fd9\u6837\u505a\uff1a<\/p>\n<p><code><br \/>\n@Override<br \/>\npublic View onCreateView(LayoutInflater inflater, ViewGroup container,<br \/>\n                         Bundle savedInstanceState) {<br \/>\n  \/\/ Inflate the layout for this fragment<br \/>\n  View rootView = inflater.inflate(R.layout.fragment_search, container, false);<br \/>\n  companyEditText = (EditText) rootView.findViewById(R.id.company_edittext);<br \/>\n  repositoryEditText = (EditText) rootView.findViewById(R.id.repository_edittext);<br \/>\n  searchButton = (Button) rootView.findViewById(R.id.search_button);<\/p>\n<p>  searchButton.setOnClickListener(new View.OnClickListener() {<br \/>\n    @Override<br \/>\n    public void onClick(View v) {<br \/>\n      searchContributors();<br \/>\n    }<br \/>\n  });<br \/>\n  return rootView;<br \/>\n}<br \/>\n<\/code><\/p>\n<p>\u5728\u4ee3\u7801\u4e2d\u9664\u4e86\u4ece\u5e03\u5c40\u4e2d\u67e5\u627e\u89c6\u56fe\uff0c\u5c06\u5b83\u4eec\u5b58\u50a8\u5728\u6d3b\u52a8\u7684\u5b57\u6bb5\u4e2d\uff0c\u4ee5\u53ca\u6dfb\u52a0\u4e00\u4e2a\u533f\u540d\u5185\u90e8\u7c7b\u4f5c\u4e3a\u76d1\u542c\u5668\u6765\u5904\u7406\u641c\u7d22\u547d\u4ee4\u4e4b\u5916\uff0c\u6ca1\u6709\u592a\u591a\u4e8b\u60c5\u53d1\u751f\u3002\u901a\u8fc7Butter Knife\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u6211\u4eec\u7684\u5de5\u4f5c\u548c\u7f16\u7801\u66f4\u5bb9\u6613\u3002\u89c6\u56fe\u5bf9\u8c61\u5b58\u50a8\u5728\u5b57\u6bb5\u4e2d\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u7b80\u5355\u5730\u5411\u6bcf\u4e2a\u5b57\u6bb5\u6dfb\u52a0Butter Knife @BindView\u6ce8\u89e3\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><code><br \/>\n@BindView(R.id.company_edittext) EditText companyEditText;<br \/>\n@BindView(R.id.repository_edittext) EditText repositoryEditText;<br \/>\n@BindView(R.id.search_button) Button searchButton;<br \/>\n<\/code><\/p>\n<p>\u6211\u4eec\u8fd8\u9700\u8981\u4f7fonCreateView\u65b9\u6cd5\u77e5\u9053Butter Knife\u7684\u5b58\u5728\u3002\u73b0\u5728\uff0c\u521d\u59cb\u5316\u4ee3\u7801\u5c06\u53ea\u5305\u542b\u4ee5\u4e0b\u7b80\u77ed\u8bed\u53e5\uff1a<\/p>\n<p><code><br \/>\n@Override<br \/>\npublic View onCreateView(LayoutInflater inflater, ViewGroup container,<br \/>\n                         Bundle savedInstanceState) {<br \/>\n  \/\/ Inflate the layout for this fragment<br \/>\n  View rootView = inflater.inflate(R.layout.fragment_search, container, false);<br \/>\n  ButterKnife.bind(this, rootView);<br \/>\n  return rootView;<br \/>\n}<br \/>\n<\/code><\/p>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u8fdb\u4e00\u6b65\uff0c\u8df3\u8fc7\u7ed1\u5b9a\u76d1\u542c\u5668\u5230searchButton\u65b9\u6cd5\uff0c\u5e76\u6539\u4e3a\u6ce8\u89e3onSearchButtonClicked\u65b9\u6cd5\uff0c\u901a\u8fc7\u795e\u5947\u5730\u5c06\u4e4b\u7ed1\u5b9a\u5230\u6309\u94ae\u70b9\u51fb\u7684@OnClick\u6ce8\u89e3\uff1a<\/p>\n<p><code><br \/>\n@OnClick(R.id.search_button)<br \/>\npublic void onSearchButtonClicked(View searchButton) {<br \/>\n  searchContributors();<br \/>\n}<br \/>\n<\/code><\/p>\n<p>\u5728\u5b98\u65b9\u7684Butter Knife\u4e3b\u9875\u8fd8\u6709\u5176\u4ed6\u7684\u4f8b\u5b50\u3002\u4e0d\u59a8\u4e00\u4e00\u67e5\u770b\u4e00\u756a\uff01\u4e00\u822c\u8bf4\u6765\uff0c\u5982\u679c\u4f60\u9700\u8981\u4ee5\u7f16\u7a0b\u65b9\u5f0f\u8bbf\u95ee\u89c6\u56fe\u5143\u7d20\uff0c\u90a3\u4e48Butter Knife\u4f1a\u8ba9\u4f60\u7684\u4ee3\u7801\u66f4\u7b80\u6d01\u548c\u53ef\u8bfb\u3002<br \/>\n<em><br \/>\n2. Ice Pick<\/em><\/p>\n<p>\u8bb8\u591aAndroid\u5e94\u7528\u7a0b\u5e8f\u9762\u4e34\u7684\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u662f\u6d3b\u52a8\u548c\u7247\u6bb5\u751f\u547d\u5468\u671f\u7684\u4e0d\u6b63\u786e\u5904\u7406\u3002\u662f\u554a\uff0c\u6211\u4eec\u77e5\u9053\uff0c\u5b83\u4e0d\u662fAndroid\u6846\u67b6\u6700\u4f18\u96c5\u7684\u90e8\u5206\u3002\u4f46\u662f\uff0c\u5728AndroidManifest\u6587\u4ef6\u4e2d\u7981\u7528\u6a2a\u5411\u6a21\u5f0f\uff0c\u8fd9\u6837\u5f53\u7528\u6237\u5c06\u8bbe\u5907\u4fa7\u5411\u79fb\u52a8\u65f6\uff0c\u5e94\u7528\u7a0b\u5e8f\u4e0d\u4f1a\u5d29\u6e83\u5e76\u975e\u662f\u4e00\u4e2a\u6b63\u786e\u7684\u89e3\u51b3\u65b9\u6848\u2014\u2014\u9996\u5148\uff0c\u56e0\u4e3a\u663e\u5f97\u6709\u70b9\u50bb\uff0c\u5176\u6b21\uff0c\u4ee3\u7801\u4e0d\u80fd\u6b63\u786e\u5904\u7406\u7684\u914d\u7f6e\u66f4\u6539\u4ecd\u7136\u4f1a\u53d1\u751f\u5e76\u7834\u574f\u4e00\u5207\uff01\u56e0\u6b64\uff0c\u4f60\u5fc5\u987b\u6b63\u786e\u5904\u7406\u5e94\u7528\u7a0b\u5e8f\u7ec4\u4ef6\u7684\u72b6\u6001\u548c\u751f\u547d\u5468\u671f\u3002<\/p>\n<p>\u5b9e\u73b0\u7684\u76ee\u7684\u662f\u5c06\u6d3b\u52a8\u4e2d\u6240\u6709\u5b57\u6bb5\u7684\u5185\u5bb9\u5b58\u50a8\u5230bundle\u4e2d\uff0c\u7136\u540e\u7531Android\u6846\u67b6\u901a\u8fc7\u751f\u547d\u5468\u671f\u6b63\u786e\u7ba1\u7406\u3002\u8fd9\u53ef\u80fd\u662f\u76f8\u5f53\u65e0\u804a\u3002<\/p>\n<p>\u5e78\u8fd0\u7684\u662f\uff0cIce Pick\u4f7f\u6211\u4eec\u7684\u751f\u6d3b\u53d8\u5f97\u5bb9\u6613\u591a\u4e86\uff0c\u56e0\u4e3a\u4f60\u518d\u4e0d\u5fc5\u4e00\u4e2a\u4e2a\u6dfb\u52a0\u6240\u6709\u7684\u53d8\u91cf\u5230bundle\u53bb\u4fdd\u5b58\u3002\u540c\u6837\u4ecebundle\u4e2d\u518d\u6b21\u8bfb\u53d6\u6570\u636e\uff0c\u5982\u679c\u5b58\u5728\uff0c\u90a3\u4e48\u4f1a\u5f88\u6709\u6311\u6218\u6027\uff0c\u4f46Ice Pick\u7b80\u5316\u4e86\u5f88\u591a\u5f88\u591a\u3002\u56e0\u6b64\uff0c\u4f5c\u4e3a\u793a\u4f8b\uff0c\u5047\u8bbe\u6211\u4eec\u9700\u8981\u8bb0\u4f4f\u6700\u540e\u4e00\u5bb6\u516c\u53f8\u548c\u5b58\u50a8\u5e93\u641c\u7d22\u7684\u7ec4\u5408\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u5bf9\u8981\u4fdd\u5b58\u5230bundle\u7684\u5b57\u6bb5\u8fdb\u884c\u6ce8\u89e3\u3002<\/p>\n<p><code><br \/>\n@State String lastSearchCombination;<br \/>\n<\/code><\/p>\n<p>\u73b0\u5728\u6211\u4eec\u9700\u8981\u5728onSaveInstanceState()\u65b9\u6cd5\u4e2d\u8c03\u7528Ice Pick\uff1a<\/p>\n<p><code><br \/>\n@Override<br \/>\npublic void onSaveInstanceState(Bundle outState) {<br \/>\n  super.onSaveInstanceState(outState);<br \/>\n  Icepick.saveInstanceState(this, outState);<br \/>\n}<br \/>\n<\/code><\/p>\n<p>\u4e5f\u5728onCreateView()\u65b9\u6cd5\u4e2d\u8c03\u7528Ice Pick\u6765\u6062\u590d\u72b6\u6001\uff1a<\/p>\n<p><code><br \/>\n@Override<br \/>\npublic View onCreateView(LayoutInflater inflater, ViewGroup container,<br \/>\n                        Bundle savedInstanceState) {<br \/>\n  \/\/ Inflate the layout for this fragment<br \/>\n  View rootView = inflater.inflate(R.layout.fragment_search, container, false);<br \/>\n  ButterKnife.bind(this, rootView);<br \/>\n  Icepick.restoreInstanceState(this, savedInstanceState);<br \/>\n  return rootView;<br \/>\n}<br \/>\n<\/code><\/p>\n<p>\u8bb0\u4f4f\uff1a\u4f60\u53ef\u4ee5\u4fdd\u5b58\u5230bundle\u7684\u5185\u5bb9\u7684\u9650\u5236\u4ecd\u7136\u5b58\u5728\u3002\u4f46\u662f\uff0c\u6ca1\u6709\u5fc5\u8981\u56e0\u4e3a\u4e3abundle\u952e\u6dfb\u52a0\u5e38\u91cf\u6216\u4e3asavedInstanceState\u6dfb\u52a0\u7a7a\u68c0\u67e5\u641e\u5f97\u4e00\u56e2\u4e71\u3002<\/p>\n<p><em>3. Dart \u548cHenson<\/em><\/p>\n<p>\u4e0eIce Pick\u7c7b\u4f3c\uff0cDart\u5e2e\u52a9\u6211\u4eec\u907f\u514d\u4e3a\u4ece\u4e00\u4e2a\u6d3b\u52a8\u4f20\u9012\u5230\u53e6\u4e00\u4e2a\u6d3b\u52a8\u7684Intent Extras\u5199\u5165\u6240\u6709\u952e\u548c\u68c0\u67e5\u3002\u5b83\u4e5f\u9002\u7528\u4e8eFragments\u3002\u8fd9\u91cc\u6709\u4e00\u4e2a\u5c0f\u4f8b\u5b50\uff0c[email protected]\u641c\u7d22\u5c4f\u5e55\u4f20\u9012\u5230\u8d21\u732e\u8005\u5217\u8868\uff0c\u5b9e\u9645\u4e0a\u5c06\u6267\u884c\u641c\u7d22\u7684\u5730\u65b9\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u4f7f\u7528@InjectExtra\u6ce8\u89e3\u5b9a\u4e49\u4e86\u4e24\u4e2a\u7c7b\u53d8\u91cf\uff1a<\/p>\n<p><code><br \/>\n@InjectExtra String repositoryQuery;<br \/>\n@InjectExtra String companyQuery;<br \/>\n<\/code><\/p>\n<p>\u4e00\u65e6Dart.inject(this, getActivity());\u88ab\u8c03\u7528\uff0c\u90a3\u4e48\u8fd9\u4e9b\u90fd\u5c06\u4f1a\u88ab\u81ea\u52a8\u521d\u59cb\u5316\u3002\u73b0\u5728\u5728Bundle\u4e2d\u88ab\u6dfb\u52a0\u5230Intent\u7684extras\u6700\u7ec8\u5c06\u5982\u4f55\u3002\u4f60\u53ef\u4ee5\u624b\u52a8\u8fdb\u884c\uff0c\u4f46\u8fd9\u91cc\u4f7f\u7528Henson\u662f\u975e\u5e38\u6709\u9053\u7406\u7684\u3002\u4e3a\u4e86\u4f7f\u5b83\u5de5\u4f5c\uff0c\u6211\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u5230\u6211\u7684SearchFragment\uff1a<\/p>\n<p><code><br \/>\nIntent intentContributorsFragment =<br \/>\n  Henson.with(getActivity())<br \/>\n        .gotoContributorsFragment()<br \/>\n        .companyQuery(companySearchKeyword)<br \/>\n        .repositoryQuery(repositorySearchKeyword).build();<br \/>\nIntent intentContributorsActivity =<br \/>\n  Henson.with(getActivity())<br \/>\n        .gotoContributorsActivity().build();<br \/>\nintentContributorsActivity.putExtras(intentContributorsFragment);<br \/>\nstartActivity(intentContributorsActivity);<br \/>\n<\/code><\/p>\n<p>\u8fd9\u7b80\u5316\u4e86\u4ee3\u7801\u4e2d\u6d3b\u52a8\u4e4b\u95f4\u7684\u901a\u4fe1\uff0c\u800c\u65e0\u9700\u6bcf\u6b21\u90fd\u624b\u52a8\u6307\u5b9a\u6bcf\u4e2atxtra\u3002<\/p>\n<p><em>4. Parceler<\/em><\/p>\n<p>Parceler\u5e2e\u52a9\u4f60\u8fdb\u884c\u5bf9\u8c61\u5e8f\u5217\u5316\u3002\u5b83\u53ef\u4ee5\u5e2e\u52a9\u4f60\u4f20\u9012\u4efb\u4f55\u5bf9\u8c61\u4f5c\u4e3aIntent extra\uff0c\u800c\u4e0d\u4f1a\u8ba9\u4f60\u9762\u5bf9\u5bf9\u8c61\u5e8f\u5217\u5316\u7684\u70e6\u607c\u3002<\/p>\n<p>\u6700\u597d\u7684\u4e8b\u60c5\u662f\uff0cIcepick\uff0cHenson\u548cDart\u4e5f\u80fd\u5f88\u597d\u5730\u548cParceler\u4e00\u8d77\u73a9\u3002\u5728\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\u793a\u4f8b\u4e2d\uff0c[email protected]Dart\u4f20\u9012Contributor\u4f5c\u4e3aIntent Extra\uff0c\u4f7f\u6211\u7684\u4ee3\u7801\u7b80\u6d01\u548c\u53ef\u8bfb\u3002<\/p>\n<p><em>5.Timber<\/em><\/p>\n<p>\u5f53\u6211\u5199\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u8fc7\u4e0d\u4e86\u4e00\u4f1a\uff0c\u6211\u603b\u6709\u72af\u9519\u8bef\u7684\u503e\u5411\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u5e94\u7528\u7a0b\u5e8f\u7684\u610f\u5916\u884c\u4e3a\u3002\u6211\u9700\u8981\u91cd\u73b0\u5b83\uff0c\u8fd9\u6837\u6211\u624d\u80fd\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u5f53\u4f60\u77e5\u9053\u91cd\u73b0\u7684\u6b65\u9aa4\u65f6\uff0c\u8c03\u8bd5\u5668\u4f1a\u5f88\u65b9\u4fbf\uff0c\u4f46\u662f\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u65e5\u5fd7\u4e5f\u5305\u542b\u4e86\u771f\u76f8\uff01<\/p>\n<p>\u5728Android\u4e2d\u5f00\u7bb1\u5373\u7528\u7684Log\u7c7b\u8db3\u591f\u597d\uff0c\u56e0\u4e3a\u53ef\u4ee5\u63d0\u4f9b\u4e0d\u540c\u7684\u65e5\u5fd7\u8bb0\u5f55\u7ea7\u522b\uff0c\u7b49\u7b49\u3002\u7136\u800c\uff0c\u6bcf\u4e2aLog.d()\u8bed\u53e5\u6709\u4e24\u4e2a\u53c2\u6570\uff1b\u9996\u5148\u662ftag\uff0c\u7b2c\u4e8c\u662fmessage\u300299\uff05\u7684\u65f6\u95f4\u91cc\uff0ctag\u5c06\u662fthis.class.getName()\uff0c\u5e76\u4e14\u4e00\u6b21\u53c8\u4e00\u6b21\u5730\u5199\u4f1a\u5f88\u70e6\u4eba\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u4f7f\u7528Timber\u5e93\uff0c\u4f60\u53ea\u8981\u8fd9\u6837\u505a\uff1a<\/p>\n<p><code><br \/>\nTimber.d(\"Informative output that needs to be logged.\");<br \/>\n<\/code><\/p>\n<p>\u2026\u5e76\u4e14\u5b83\u5c06\u4e3a\u4f60\u63d0\u4f9b\u6b63\u786e\u7684\u9ed8\u8ba4tag\uff01\u6b64\u5916\uff0c\u8bf7\u8bb0\u4f4f\uff0c\u4f60\u9700\u8981\u5728\u4f7f\u7528\u4e4b\u524d\u521d\u59cb\u5316Timber\u3002\u67e5\u770b\u6211\u5df2\u6dfb\u52a0\u8c03\u7528\u7684ContributorsApplication.onCreate()\u4ee3\u7801\uff1a<\/p>\n<p><code><br \/>\nTimber.plant(new Timber.DebugTree());<br \/>\n<\/code><\/p>\n<p>\u8fd9\u5c31\u662f\u6b63\u786e\u521d\u59cb\u5316Timber\u6240\u6709\u9700\u8981\u505a\u7684\u4e8b\u60c5\uff0c\u6240\u6709\u6ca1\u6709\u7406\u7531\u4f60\u7684app\u4e0d\u4f7f\u7528Timber\u3002<br \/>\n<em><br \/>\n6.Dagger\u548cDagger2<\/em><\/p>\n<p>\u6700\u540e\uff0c\u4f46\u5e76\u975e\u6700\u4e0d\u91cd\u8981\u7684\uff0cDagger\u548cDagger2\u5e93\u5728app\u4e2d\u7ba1\u7406\u4f9d\u8d56\u6ce8\u5165\u7684\u8868\u73b0\u771f\u4ee4\u4eba\u60ca\u53f9\u3002\u4e3a\u4f60\u5904\u7406\u4f9d\u8d56\u6ce8\u5165\u662f\u7f16\u5199\u4ee3\u7801\u7684\u8d85\u68d2\u505a\u6cd5\u3002\u4f60\u6307\u5b9a\u5e94\u7528\u7a0b\u5e8f\u7684\u7ec4\u4ef6\u4ee5\u53ca\u5b83\u4eec\u5e94\u5982\u4f55\u76f8\u4e92\u4ea4\u4e92\u3002\u4f60\u53ef\u4ee5\u5b9a\u4e49\u4ee3\u7801\u7684\u54ea\u4e9b\u90e8\u5206\u9700\u8981\u5176\u4ed6\u90e8\u4ef6\u7684\u5de5\u4f5c\uff0c\u77a7\uff0c\u8fd9\u4e2a\u5e93\u5c06\u4e3a\u4f60\u521d\u59cb\u5316\u5b50\u90e8\u4ef6\uff0c\u5e76\u6839\u636e\u9700\u8981\u6ce8\u5165\u5b83\u4eec\u3002\u4f60\u53ef\u4ee5\u68c0\u67e5\u793a\u4f8b\u9879\u76ee\u4ee3\u7801\u4ee5\u67e5\u770b\u4f7f\u7528\u793a\u4f8b\u3002<\/p>\n<p>\u7136\u800c\uff0cDagger\u548cDagger 2\u6d89\u53ca\u9762\u592a\u5e7f\u6cdb\u4e86\uff0c\u6240\u4ee5\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\u6211\u4eec\u5c31\u4e0d\u505a\u8be6\u7ec6\u89e3\u91ca\u4e86\u3002\u5982\u679c\u4f60\u60f3\u4ece\u4f7f\u7528Dagger\u5f00\u59cb\uff0c\u90a3\u4e48\u6709\u4e00\u4e2a\u5f88\u597d\u7684\u4ee3\u7801\u4f8b\u5b50\uff0ccoffee maker\uff0c\u5b83\u4e5f\u5f97\u5230\u4e86\u4f18\u79c0\u7684\u6ce8\u91ca\u652f\u6301\u3002<\/p>\n<p><em>\u7ed3\u8bba<\/em><\/p>\n<p>\u6709\u5f88\u591a\u6709\u8da3\u7684Android\u5e93\uff0c\u6211\u5728\u8fd9\u91cc\u53ea\u5217\u51fa\u4e86\u4e00\u4e9b\u3002\u5b89\u88c5\u8d77\u6765\u76f8\u5f53\u5bb9\u6613\uff0c\u56e0\u4e3a\u4f60\u53ea\u9700\u8981\u6307\u5b9a\u4f9d\u8d56\u5173\u7cfb\u5c31\u53ef\u4ee5\u4e86\u3002\u8fd9\u4e9b\u90fd\u662f\u88ab\u79ef\u6781\u7ef4\u62a4\u7684\u9879\u76ee\uff0c\u6240\u4ee5\u5b83\u4eec\u6709\u4f1f\u5927\u7684\u6587\u6863\u3002<\/p>\n<p>\u4f60\u8981\u505a\u7684\u5c31\u662f\u5c0f\u5fc3\u6784\u5efa\u8fc7\u7a0b\u3002\u5f53\u4f60\u5f00\u59cb\u7ed3\u5408\u591a\u4e2a\u5e93\u4e0e\u6ce8\u89e3\u5904\u7406\u5668\u65f6\uff0c\u786e\u4fdd\u4f7f\u7528provided()\u6216annotationprocessor()\uff0c\u800c\u4e0d\u662f\u5728build.gradle\u4e2d\u5c06\u5b83\u4eec\u7ed3\u5408\u8d77\u6765.<\/p>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\uff0c\u6211\u4eec\u5c06\u770b\u770b6\u4e2a\u53ef\u4ee5\u5e2e\u52a9\u4fdd\u6301\u4ee3\u7801\u6e05\u6670\u548c\u53ef\u8bfb\u6027\u7684Android\u5e93\uff0c\u5e76\u4e14\u4f7f\u7528\u793a\u4f8b\u9879\u76ee\u4ee5\u65b9\u4fbf\u4f60\u53ef\u4ee5\u770b\u5230\u5e93\u7684\u4f5c\u7528\u3002<\/p>\n","protected":false},"author":1,"featured_media":965,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[326],"class_list":["post-963","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-development-of-communication-technology","tag-android-"],"post_thumbnail_image":"http:\/\/images.jiandaima.com\/blog\/wp-content\/uploads\/2017\/01\/14845393411.png?imageView2\/1\/w\/300\/h\/300#","content_first_image":"http:\/\/images.jiandaima.com\/blog\/wp-content\/uploads\/2017\/01\/14845393411.png","post_medium_image_300":"http:\/\/images.jiandaima.com\/blog\/wp-content\/uploads\/2017\/01\/14845393411.png","post_thumbnail_image_624":"http:\/\/images.jiandaima.com\/blog\/wp-content\/uploads\/2017\/01\/14845393411.png","post_frist_image":"http:\/\/images.jiandaima.com\/blog\/wp-content\/uploads\/2017\/01\/14845393411.png","post_medium_image":"http:\/\/images.jiandaima.com\/blog\/wp-content\/uploads\/2017\/01\/14845393411.png","post_large_image":"http:\/\/images.jiandaima.com\/blog\/wp-content\/uploads\/2017\/01\/14845393411.png","post_full_image":"http:\/\/images.jiandaima.com\/blog\/wp-content\/uploads\/2017\/01\/14845393411.png","post_all_images":[{"imagesurl":"http:\/\/images.jiandaima.com\/blog\/wp-content\/uploads\/2017\/01\/14845393411-163x300.png","id":"image0"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":5,"total_comments":0,"category_name":"\u5f00\u53d1\u6280\u672f\u4ea4\u6d41","post_date":"2017-01-19","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"http:\/\/images.jiandaima.com\/blog\/wp-content\/uploads\/2020\/02\/img_5e44112722964.png","avatarurls":[],"related_posts":[],"pageviews":742,"next_post_id":1142,"next_post_title":"\u67d0\u7535\u5b50\u5546\u52a1\u7f51\u7ad9\u8d2d\u7269\u8f66\u4fc3\u9500\u4f18\u60e0java\u7b97\u6cd5","previous_post_id":945,"previous_post_title":"Unity\u662f\u5982\u4f55\u8f93\u51fa\u5230\u591a\u5e73\u53f0\u7684\uff1f","_links":{"self":[{"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/posts\/963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/comments?post=963"}],"version-history":[{"count":0,"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/posts\/963\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/media\/965"}],"wp:attachment":[{"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/media?parent=963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/categories?post=963"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/tags?post=963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}