{"id":982,"date":"2014-10-10T14:52:41","date_gmt":"2014-10-10T06:52:41","guid":{"rendered":"http:\/\/www.yeetrack.com\/?p=982"},"modified":"2014-10-10T14:52:41","modified_gmt":"2014-10-10T06:52:41","slug":"android%e4%bb%a3%e7%a0%81%e6%b3%a8%e5%85%a5%e6%a1%86%e6%9e%b6roboguice","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=982","title":{"rendered":"Android\u4ee3\u7801\u6ce8\u5165\u6846\u67b6RoboGuice"},"content":{"rendered":"<h1>Android\u4ee3\u7801\u6ce8\u5165\u6846\u67b6RoboGuice<\/h1>\n<h2>\u6982\u8ff0<\/h2>\n<p>RoboGuice 2\u53ef\u4ee5\u8ba9\u6211\u4eec\u66f4\u65b9\u4fbf\u3001\u5feb\u6377\u5730\u7f16\u5199android\u4ee3\u7801\u3002\u5728\u5199android\u4ee3\u7801\u65f6\uff0c\u6211\u4eec\u5728\u4f7f\u7528<code>getIntent().getExtras()<\/code>\u53ef\u80fd\u4f1a\u5fd8\u8bb0\u5224\u7a7a\uff0c<code>findViewById()<\/code>\u5fc5\u987b\u5f3a\u5236\u8f6c\u6362\u6210<code>TextView<\/code>\u5f88\u522b\u626d\uff1fRobotGuice 2\u53ef\u4ee5\u5e2e\u6211\u4eec\u7701\u6389\u8fd9\u4e9b\u6b65\u9aa4\u3002<\/p>\n<p>RoboGuice 2\u53ef\u4ee5\u6ce8\u5165\u5230View,Resource,System Service\u6216\u8005\u5176\u4ed6\u4efb\u4f55\u5bf9\u8c61\u4e2d\uff0c\u6211\u4eec\u4e0d\u5fc5\u5728\u5173\u5fc3\u8fd9\u4e9b\u7ec6\u8282\u3002<!--more--><\/p>\n<p>\u4f7f\u7528RoboGuice 2\u53ef\u4ee5\u7cbe\u7b80\u6211\u4eec\u7684\u4ee3\u7801\uff0c\u8fd9\u6837\u4f1a\u51cf\u5c11bug\u6570\u91cf\uff0c\u4e5f\u4f7f\u7a0b\u5e8f\u66f4\u52a0\u6613\u8bfb\u3002\u5728\u7f16\u7801\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u7cbe\u529b\u66f4\u591a\u5730\u653e\u5728\u4e1a\u52a1\u903b\u8f91\u4e0a\u3002<\/p>\n<h2>\u4f7f\u7528\u65b9\u6cd5<\/h2>\n<p>RobotGuice\u4f7f\u7528google\u81ea\u5df1\u7684Guice\uff0c\u8ba9\u5b89\u5353\u652f\u6301\u4f9d\u8d56\u6ce8\u5165\uff0c\u7c7b\u4f3c\u4e8eSpring\u3002<\/p>\n<p>\u4f20\u7edf\u7684android\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code>    class AndroidWay extends Activity { \n        TextView name; \n        ImageView thumbnail; \n        LocationManager loc; \n        Drawable icon; \n        String myName; \n\n        public void onCreate(Bundle savedInstanceState) { \n            super.onCreate(savedInstanceState); \n            setContentView(R.layout.main);\n            name      = (TextView) findViewById(R.id.name); \n            thumbnail = (ImageView) findViewById(R.id.thumbnail); \n            loc       = (LocationManager) getSystemService(Activity.LOCATION_SERVICE); \n            icon      = getResources().getDrawable(R.drawable.icon); \n            myName    = getString(R.string.app_name); \n            name.setText( \"Hello, \" + myName ); \n        } \n    } \n<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u517119\u884c\u3002\u5982\u679c\u6211\u4eec\u60f3\u9605\u8bfbonCreate()\u65b9\u6cd5\uff0c\u5f97\u7565\u8fc7\u4e0a\u9762\u7684\u53d8\u91cf\u521d\u59cb\u5316\u533a\u57df\uff0c\u5176\u5b9eonCreate\u65b9\u6cd5\u5c31\u4e00\u6837\u4ee3\u7801<code>name.setText()<\/code>\uff0c\u4ee3\u7801\u770b\u8d77\u6765\u5f88\u81c3\u80bf\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4f7f\u7528RoboGuice\u7684\u4ee3\u7801\uff1a<\/p>\n<pre><code>    @ContentView(R.layout.main)\n    class RoboWay extends RoboActivity { \n        @InjectView(R.id.name)             TextView name; \n        @InjectView(R.id.thumbnail)        ImageView thumbnail; \n        @InjectResource(R.drawable.icon)   Drawable icon; \n        @InjectResource(R.string.app_name) String myName; \n        @Inject                            LocationManager loc; \n\n        public void onCreate(Bundle savedInstanceState) { \n            super.onCreate(savedInstanceState); \n            name.setText( \"Hello, \" + myName ); \n        } \n    } \n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>onCreate()<\/code>\u65b9\u6cd5\u5c31\u7b80\u6d01\u591a\u4e86\uff0c\u6240\u6709\u521d\u59cb\u5316\u4ee3\u7801\u90fd\u88ab\u79fb\u9664\uff0c\u53ea\u5269\u4e0b\u6211\u4eec\u7684\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u3002\u9700\u8981<code>SystemServce<\/code>\uff1f\u6ce8\u5165\u5373\u53ef\u3002\u9700\u8981<code>View<\/code>\u6216\u8005<code>Resource<\/code>\uff1f\u6ce8\u5165\u5373\u53ef\uff0cRoboGuice\u4f1a\u5e2e\u6211\u4eec\u5b9e\u73b0\u90a3\u4e9b\u7ec6\u8282\u3002<\/p>\n<p>RoboGuice\u7684\u76ee\u6807\u662f\u8ba9\u6211\u4eec\u7684\u4ee3\u7801\u771f\u6b63\u5173\u4e4e\u4e8eapp\uff0c\u800c\u4e0d\u662f\u7ef4\u62a4\u7740\u4e00\u5806\u5806\u7684\u521d\u59cb\u5316\u3001\u751f\u547d\u5468\u671f\u63a7\u5236\u4ee3\u7801\u7b49\u3002<\/p>\n<p>\u66f4\u591a\u4fe1\u606f<a href=\"https:\/\/github.com\/roboguice\/roboguice\/tree\/master\/astroboy\">https:\/\/github.com\/roboguice\/roboguice\/tree\/master\/astroboy<\/a>)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android\u4ee3\u7801\u6ce8\u5165\u6846\u67b6RoboGuice \u6982\u8ff0 RoboGuice 2\u53ef\u4ee5\u8ba9\u6211\u4eec\u66f4\u65b9\u4fbf\u3001\u5feb\u6377\u5730\u7f16\u5199android\u4ee3\u7801\u3002\u5728\u5199android\u4ee3\u7801\u65f6\uff0c\u6211\u4eec\u5728\u4f7f\u7528getIntent().getExtras&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[33],"tags":[43,8,7],"class_list":["post-982","post","type-post","status-publish","format-standard","hentry","category-coding","tag-android","tag-java","tag-7"],"views":3883,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/982","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=982"}],"version-history":[{"count":1,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/982\/revisions"}],"predecessor-version":[{"id":983,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/982\/revisions\/983"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}