ãã®èšäºã§ã¯ãAndroidã¢ããªã±ãŒã·ã§ã³ã®ã¢ãŒããã¯ãã£ãŒã®äž»èŠãªããã£ã©ã¯ã¿ãŒãã玹ä»ããŸãã
äžè¬ã«ãAndroidã¢ããªã±ãŒã·ã§ã³ã¯æ¬¡ã®ãã®ã§æ§æãããŸãã
- Android SDKã®ã¡ã€ã³ã¯ã©ã¹ïŒ View ã Activity ã ContentProvider ã Service ã BroadcastReciever ã Intent ïŒã®ãµãã¯ã©ã¹ã§ããJavaã¯ã©ã¹ãšãAndroid SDKã«èŠªãæããªãJavaã¯ã©ã¹ã
- ã¢ããªã±ãŒã·ã§ã³ãããã§ã¹ã
- æååãç»åãªã©ã®ãªãœãŒã¹
- ãã¡ã€ã«
Javaã¯ã©ã¹
次ã®å³ã¯ãéçºè ã察åŠããªããã°ãªããªãAndroid SDKã®ã¡ã€ã³ã¯ã©ã¹ã®éå±€ã瀺ããŠããŸãã
å®éãããã«å€ãã®ã¯ã©ã¹ããããŸããããããã¯äž»ãªã¯ã©ã¹ã§ãã é»è²ã§åŒ·èª¿è¡šç€º-éçºè ãçŽæ¥äœæ¥ããŠãããã®ïŒç¹ã«ããããããç¶æ¿ããããã®ïŒã æ®ããåæ§ã«éèŠã§ãããçŽæ¥äœ¿çšãããããšã¯ããŸããããŸããã
ãã¥ãŒã¯ããã¹ãŠã®ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãŠã£ãžã§ããïŒGUIãŠã£ãžã§ããïŒã®åºæ¬ã¯ã©ã¹ã§ãã Androidã¢ããªã±ãŒã·ã§ã³ã€ã³ã¿ãŒãã§ã€ã¹ã¯ããã®ã¯ã©ã¹ã®åå«ã®ã€ã³ã¹ã¿ã³ã¹ã®ããªãŒã§ãã ãã®ããªãŒã¯ããã°ã©ã ã§äœæã§ããŸãããééã£ãŠããŸãã ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã¯XMLïŒã¬ã€ã€ãŒãã¡ã€ã«ãã¬ã€ã¢ãŠããã¡ã€ã«ïŒã䜿çšããŠå®çŸ©ãããå®è¡æã«èªåçã«ïŒinflateãAndroidçšèªïŒå¯Ÿå¿ãããªããžã§ã¯ãã®ããªãŒã«å€ãããŸãã
Activityã¯ã©ã¹ãšãã®ãµãã¯ã©ã¹ã«ã¯ããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã®èåŸã«ããããžãã¯ãå«ãŸããŠããŸãã 詳现ã«èª¿ã¹ããšããã®ã¯ã©ã¹ã¯Model-View-ViewModel ïŒMVVMïŒã¢ãŒããã¯ãã£ãã³ãã¬ãŒãã®ViewModelã«å¯Ÿå¿ããŠããŸãã Activityãµãã¯ã©ã¹ãšãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã®é¢ä¿ã¯ã1察1ã®é¢ä¿ã§ãã éåžžãåActivityãµãã¯ã©ã¹ã«ã¯1ã€ã®ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã¬ã€ã€ãŒã®ã¿ãé¢é£ä»ãããããã®éãåæ§ã§ãã ã¢ã¯ãã£ããã£ã«ã¯ã©ã€ããµã€ã¯ã«ããããŸãã
ã©ã€ããµã€ã¯ã«äžãã¢ã¯ãã£ããã£ã¯æ¬¡ã®3ã€ã®ç¶æ ã®ããããã«ãªããŸãã
- ã¢ã¯ãã£ãã§å®è¡äž-ãã®ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã¯ãã©ã¢ã°ã©ãŠã³ãïŒæè¡çã«èšãã°ãã¢ã¯ãã£ããã£ã¹ã¿ãã¯ã®æäžéšïŒã«ãããŸã
- äžæåæ¢-ãã®ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ããã©ãŒã«ã¹ã倱ã£ããããŸã 衚瀺ãããŠããå Žåã ãã®ç¶æ ã§ã¯ãã³ãŒãã¯å®è¡ãããŸããã
- çµäº-ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã衚瀺ãããŠããªãå Žåã ãã®ç¶æ ã§ã¯ãã³ãŒãã¯å®è¡ãããŸããã
ã¢ã¯ãã£ããŒã·ã§ã³ã³ãŒãã¯ã察å¿ãããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã衚瀺ããããã©ãŒã«ã¹ãããå Žåã«ã®ã¿å®è¡ãããŸãã ã¢ã¯ãã£ããã£ãäžæåæ¢ãŸãã¯å®äºãããšãã«ã¢ã¯ãã£ããã£ãªããžã§ã¯ããšãã®é¢é£ãªããžã§ã¯ããã¡ã¢ãªå ã«ãããšããä¿èšŒã¯ãããŸããïŒãããèŠããŠããããšã¯éåžžã«éèŠã§ãã å ã»ã© Androidã®ã¡ã¢ãªç®¡çã®ãã®ç¹ã«ã€ããŠèª¬æããŸããïŒã
ContentProviderã¯ã©ã¹ãšãã®ãµãã¯ã©ã¹ã¯ãMVVMã¢ãŒããã¯ãã£ã®ã¢ãã«ãè¡šããŸãã ã»ãšãã©ã®å®çšçãªã±ãŒã¹ã§ã¯ãããã¯å°ã掟æãªURIããŒã¹ã®ã¢ã¯ã»ã¹æ¹æ³ãåããSQLiteããŒã¿ããŒã¹ã®ã©ãããŒã§ãã çè«çã«ã¯ãããŒã¿ããŒã¹ä»¥å€ã«åºã¥ããŠContentProviderãäœæããããšãéçºè ã«è¿·æãããããšã¯ãããŸããã ãã ããæ¢åã®ã³ã³ãã³ããããã€ããŒã®queryïŒïŒã¡ãœããã¯Cursorãªããžã§ã¯ããè¿ããŸããããã¯ãJDBC ResultSetã€ã³ã¿ãŒãã§ã€ã¹ãšãã®åäœã«éåžžã«äŒŒãŠããŸãã ãããã£ãŠãã³ã³ãã³ããããã€ããŒã®çã®ç®çãããŒã¿ããŒã¹ã®ã«ãã»ã«åã§ããããšã誰ããçãããšã¯ãªãã§ãããã
AndroidããŒã ããã®èšèšã«ã©ã®ããã«ãªã£ãã®ãã¯ããããŸããããç§ã®æèŠã§ã¯ã2ã€ã®è¯ãããããäºææ§ã®ãªãã¢ã€ãã¢ãããã«ã€ãªãã£ãŠããŸãã
ãããç§ãããæãçç±ã§ãã ã³ã³ãã³ããããã€ããŒã®åºæ¬çãªèãæ¹ã¯ãAJAXã¢ããªã±ãŒã·ã§ã³ã®ã¢ãŒããã¯ãã£ã«åºã¥ããŠããããã§ãã AJAXã¢ããªã±ãŒã·ã§ã³ã¯éåžžãã¢ãã«ããµãŒããŒåŽURIãšããŠè¡šãããMVVMã¢ãŒããã¯ãã£ã䜿çšããŸãïŒãã ããããã¯ããŒã¿ãããŒã«ã«ã«ä¿åã§ããHTML5ã§å€æŽãããŸããïŒã å®éãã³ã³ãã³ããããã€ããŒãURIã䜿çšããŠèŠæ±ãããMIMEã¿ã€ãã䜿çšããŠæ¡åŒµæ©èœãäœæãããšããäºå®ã¯ãAJAXãã³ã¢ã§ããããšã瀺ããŠããŸãã Googleã®ã¹ã¿ãããGmailãGoogle Docsãªã©ã®å€æ°ã®AJAXã¢ããªã±ãŒã·ã§ã³ãäœæããããšãæãåºããŠãã ãããã¢ã€ãã¢ãAJAXã¢ãŒããã¯ãã£ããåçšãããããšã¯ããèªç¶ãªããšã§ãã
ä»ã®èª°ããå¥ã®çŽ æŽãããã¢ã€ãã¢ãæãã€ããã®ãããããŸãããã¢ãã€ã«ããã€ã¹äžã«å®å šãªãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ãä¿æããããšã¯çŽ æŽãããããšã§ãã ïŒããã¯ãæºåž¯é»è©±ãçŸåšããããã£ãšåŒ±ãã£ã2005幎é ã§ããïŒã ãããŠããã®çµæã圌ãã¯2ã€ã®åªããã¢ã€ãã¢ã1ã€ã®ContentProviderã¯ã©ã¹ã«çµåããŸããã éåžžã®ãœãããŠã§ã¢éçºã®å Žåãšåæ§ã«ã2ã€ã®åªããã¢ã€ãã¢ãçµã¿åãããŠããå¿ ãããåªããã¢ã€ãã¢ãåŸããããšã¯éããŸããã Androidã®å Žåãã³ã³ãã³ããããã€ããŒã«ã¯ããæå°æªãªãã¶ã€ã³ããããŸãã
Serviceã¯ã©ã¹ãšãã®ãµãã¯ã©ã¹ã¯ãã©ããããããåé¡ããã®ãé£ãããšæããŸãã Googleã®äººãã¡ãåãåé¡ã«çŽé¢ããŠãããšæããŸãïŒããã¥ã¡ã³ããèªãã§ãã ããïŒã 圌ãã®åé¡ã¯åºæ¬çã«ãã®ã¯ã©ã¹ãäœã§ãªããã瀺ããŠããŸãã å人çã«ã¯ããµãŒãã¹ã¯ã¢ãã«ã®ããªãšãŒã·ã§ã³ã§ãããContentProviderãšã¯ãããã«ç°ãªããŠãŒã¹ã±ãŒã¹ãæäŸãããšèããŠããŸãã
ç§ã®æèŠã§ã¯ãAndroidãµãŒãã¹ã®ã¢ãŒããã¯ãã£èšèšã¯OSGIãµãŒãã¹ã«è§ŠçºãããŠããŸã ã
ãã®ãµãŒãã¹ã¯ãAndroidã¹ã¬ããã¢ãã«ã«ãã£ãŠçããè«ççãªåé¡ã®è§£æ±ºçãšããŠãGoogleã®ã¹ã¿ããã«ãã£ãŠäœæããããšæããŸãã
èããŠã¿ãŠãã ããïŒã¢ã¯ãã£ããã£ã¯ã¢ã¯ãã£ãã§ããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ããã©ã¢ã°ã©ãŠã³ãã«ããå Žåã«ã®ã¿å®è¡ãããŸãã å¥ã®ã¢ã¯ãã£ããã£ã®ã€ã³ã¿ãŒãã§ã€ã¹ãçŸåšã®ã¢ã¯ãã£ããã£ãéãããšããã«ãçŸåšã®ã¢ã¯ãã£ããã£ãäœããå®è¡ããŠããŠããåŸè ã¯åæ¢ããŸãã ãããããããå®è¡ããããã»ã¹ããã©ã¢ã°ã©ãŠã³ãã«ãªãå Žåã§ããäœããã®æäœãå®è¡ããå¿ èŠãããå Žåã¯ã©ãã§ããããïŒ ã¢ã¯ãã£ããã£ã§ã¯ããããè¡ãããšã¯ã§ããŸããã ContentProviderã«ã¯ç¬èªã®ã©ã€ããµã€ã¯ã«ããªããããContentProviderã䜿çšããŠãããè¡ãããšã¯ã§ããŸãããContentProviderã䜿çšããã¢ã¯ãã£ããã£ãã¢ã¯ãã£ããªéã®ã¿å®è¡ã§ããŸãã
ãããŠãããã§ãµãŒãã¹ãå©ãã«ãªããŸãã ãããã¯ãäœæ¥ãè¡ãããã»ã¹ããã©ã¢ã°ã©ãŠã³ãã«ãªãå Žåã§ãå®è¡ã§ããŸãã ãããã£ãŠãããã¯ã°ã©ãŠã³ãã§äœæ¥ããŠããå Žåã§ãçµäºããå¿ èŠãããã¿ã€ã ã¹ãã¬ããæäœãå®è¡ããã¢ã¯ãã£ããã£ãéçºããŠããå Žåããã®æäœãå®è£ ãããµãŒãã¹ãäœæããã¢ã¯ãã£ããã£ããéå§ããå¿ èŠããããŸãã
ãµãŒãã¹ã«ã¯ã©ã€ããµã€ã¯ã«ããããŸãã ããã¯ãäžå®ã®æ¡ä»¶äžã§Androidã¢ããªã±ãŒã·ã§ã³ã«ãã£ãŠã€ã³ã¹ã¿ã³ã¹åããã³èµ·åã§ããããšãæå³ããŸãïŒããã«ã€ããŠã¯åŸã§èª¬æããŸãïŒã
åè¿°ããããã«ãã¢ãã«ã®ãããªãµãŒãã¹ã«ã¯ãContentProvierãããäžè¬çãªç®æšããããŸãã ããŒã¿ããŒã¹ã䜿çšã§ããŸãããContentProviderã®å Žåã®ããã«ããã®APIã¯ããŒã¿ããŒã¹ã«é¢é£ããŠããŸããã ã»ãšãã©ã®å ŽåããµãŒãã¹ã¯å€éšãµãŒããŒãšã®éä¿¡ã«äœ¿çšãããŸãã
BroadcastReceiverã¯ã©ã¹ãšãã®ãµãã¯ã©ã¹ã¯ãAndroidã¢ãŒããã¯ãã£ã«å®è£ ããããããªãã·ã£ãŒ/ãµãã¹ã¯ã©ã€ããŒã€ã³ã¿ã©ã¯ã·ã§ã³ã¡ã«ããºã ã®ããµãã¹ã¯ã©ã€ããŒããè¡šããŸãã
åã®èšäºã§çžäºäœçšã®ã¡ã«ããºã ã«ã€ããŠã¯ãã§ã«èª¬æããŸããã
ãã¡ãããAndroidéçºè ã¯ãAndroid SDKããã¯ã©ã¹ãæ¡åŒµããã ãã§ã¯ãããŸããã 圌ã¯èªåã®ã¯ã©ã¹ã奜ããªããã«æžãããšãã§ããŸãã ãã ãããããã¯ãã¹ãŠAndoird SDKã®ã¯ã©ã¹ã®ããã«ããŒã¯ã©ã¹ãã«ãããŸããã
Androidãããã§ã¹ã
Androidãããã§ã¹ãã¯ãAndroidã¢ããªã®ãã1ã€ã®éèŠãªéšåã§ãã ãã®ã¢ã€ãã¢ã¯ãEclipseã®ãã©ã°ã€ã³ãããã§ã¹ãã«è§ŠçºãããŸããã
Androidãããã§ã¹ãã¯XMLãã¡ã€ã«ã§ãããããã€ãã®æ©èœãå®è¡ããŸãã Googleããããã説æããæ¹æ³ã¯æ¬¡ã®ãšããã§ãã
- Javaã¢ããªã±ãŒã·ã§ã³ããã±ãŒãžã®ååãå®çŸ©ããŸãã ããã±ãŒãžåã¯ãã¢ããªã±ãŒã·ã§ã³ã®äžæã®èå¥åã§ãã
- ã¢ããªã±ãŒã·ã§ã³ã®ã³ã³ããŒãã³ãïŒã¢ã¯ãã£ããã£ããµãŒãã¹ãæŸéåä¿¡æ©ãã³ã³ãã³ããããã€ããŒïŒã«ã€ããŠèª¬æããŸãã åã³ã³ããŒãã³ããå®è£ ããã¯ã©ã¹åã決å®ãããã®æ©èœïŒããšãã°ãåŠçã§ããIntentã¡ãã»ãŒãžãªã©ïŒãéç¥ããŸãã ãããã®çºè¡šã«ãããAndroidã·ã¹ãã ã¯ã©ã®ã³ã³ããŒãã³ãããã³ã©ã®æ¡ä»¶ã§èµ·åã§ããããç¥ãããšãã§ããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã³ã³ããŒãã³ããå«ãããã»ã¹ãå®çŸ©ããŸãã
- APIã®ä¿è·ãããéšåã«ã¢ã¯ã»ã¹ããä»ã®ã¢ããªã±ãŒã·ã§ã³ãšå¯Ÿè©±ããããã«ãã¢ããªã±ãŒã·ã§ã³ã«å¿ èŠãªã¢ã¯ã»ã¹èš±å¯ã宣èšããŸãã
- ãŸããã¢ããªã±ãŒã·ã§ã³ã³ã³ããŒãã³ãã«ã¢ã¯ã»ã¹ããããã«å¿ èŠãªæš©éã宣èšããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã®å®è¡äžã«ãããã¡ã€ãªã³ã°ããã®ä»ã®æ å ±ãæäŸããã€ã³ã¹ãã«ã¡ã³ããŒã·ã§ã³ã¯ã©ã¹ãåæããŸãã ãããã®å®£èšã¯ãã¢ããªã±ãŒã·ã§ã³ã®éçºããã³ãã¹ãäžã«ã®ã¿ãããã§ã¹ãã«ååšããŸãã ã¢ããªã±ãŒã·ã§ã³ãå ¬éãããåã«åé€ãããŸãã
- ã¢ããªã±ãŒã·ã§ã³ãå¿ èŠãšããAndroid APIã®æå°ã¬ãã«ãçºè¡šããŸãã
- ã¢ããªã±ãŒã·ã§ã³ãé¢é£ä»ããã©ã€ãã©ãªãŒããªã¹ãããŸãã
2çªç®ã®ç¹ã«æ³šæããŠãã ããã ç¹å®ã®ã¯ã©ã¹ãã¢ããªã±ãŒã·ã§ã³ã®ActivityãContentProviderãBroadcastReceiverããŸãã¯Serviceãæ¡åŒµããå Žåããããã§ã¹ãã«èšè¿°ããããŸã§ãã®ã¯ã©ã¹ã¯äœ¿çšã§ããŸããã
è³æº
äœããã®åœ¢åŒã®ææ°ã®GUIã¢ããªã±ãŒã·ã§ã³ã¯ãã¹ãŠããªãœãŒã¹ã䜿çšããŸãã Androidã¢ããªãäŸå€ã§ã¯ãããŸããã 次ã®ã¿ã€ãã®ãªãœãŒã¹ã䜿çšããŸãã
- ç»å
- GUIã¬ã€ã€ãŒïŒXMLãã¡ã€ã«ïŒ
- ã¡ãã¥ãŒå®£èšïŒXMLãã¡ã€ã«ïŒ
- ããã¹ãæåå
ãªãœãŒã¹ãAndroidã¢ããªã«é¢é£ä»ããããæ¹æ³ã¯çããããšã§ãã éåžžãJavaã§ã¯ããªãœãŒã¹ã¯æååã«ãã£ãŠèå¥ãããŸãã ãã®ãããªè¡ã«ã¯ãããšãã°ãç»åãå«ããã¡ã€ã«ã®ãã¹ãšååããŸãã¯ãã®è¡ã®IDãªã©ãå«ãŸããŸãã åé¡ã¯ãã³ãŒãå€æäžã«ãã®ãããªãªã³ã¯ã®ãšã©ãŒãæ€åºã§ããªãããšã§ãã
次ã®äŸãèŠãŠã¿ãŸãããã mybutton.pngãšããååã®ãã¡ã€ã«ã«ã¯ããã¿ã³ã®ç»åãå«ãŸããŠããŸãã éçºè ã¯ãã¹ãç¯ããã³ãŒããããªãœãŒã¹ãåç §ããŠmybuton.pngããã€ã€ã«ããŸãã ãã®çµæãã³ãŒãã¯ååšããªããªãœãŒã¹ã䜿çšããããšããŸãããã³ã³ãã€ã«ã¯æåããŸãã ãšã©ãŒã¯ãã¹ãäžã«ã®ã¿æ€åºã§ããŸãïŒãŸãã¯ãŸã£ããæ€åºãããªãå ŽåããããŸãïŒã
Googleã®ã¹ã¿ããã¯ããã®åé¡ã®ãšã¬ã¬ã³ããªè§£æ±ºçãèŠã€ããŸããã Androidã¢ããªã±ãŒã·ã§ã³ããã«ããããšã R ïŒ1æåã®ã¿ïŒãšããååã®ç¹å¥ãªJavaã¯ã©ã¹ãçæãããŸãã ãã®ã¯ã©ã¹ã«ã¯ãããã€ãã®éçãªæçµããŒã¿ã»ãããå«ãŸããŸãã ãã®ãããªåããŒã¿ã»ããã¯ãåå¥ã®ãªãœãŒã¹ãžã®ãªã³ã¯ã§ãã ãããã®ãªã³ã¯ã¯ããªãœãŒã¹ãšéä¿¡ããããã«ã¢ããªã±ãŒã·ã§ã³ã³ãŒãã§äœ¿çšãããŸãã ããã§ããªãœãŒã¹ãžã®ãªã³ã¯å ã®ãšã©ãŒã¯ãã¹ãŠãã³ã³ãã€ã«ããã»ã¹ã§æããã«ãªããŸãã
ãã¡ã€ã«
Androidã¢ããªã±ãŒã·ã§ã³ã¯ãããã€ãã®ç°ãªããã¡ã€ã«ã¿ã€ãã䜿çšããŸãã
- æ±çšãã¡ã€ã«
- Dbãã¡ã€ã«
- Opaque Binary BlobïŒ OBB ïŒ ãã¡ã€ã« ïŒã¢ããªã±ãŒã·ã§ã³çšã«ããŠã³ãã§ããæå·åããããã¡ã€ã«ã·ã¹ãã ã§ãïŒ
- ãã£ãã·ã¥ããããã¡ã€ã«
ãã¡ããããããã¯ãã¹ãŠLinuxãã¡ã€ã«ã«ãããŸããããããŸããŸãªAPIãšåå¥ã®ã¹ãã¬ãŒãžã§åŠçããå Žåã«ã®ã¿ãããããåå¥ã®ãã¡ã€ã«ã¿ã€ããšèŠãªãããšã¯çã«ããªã£ãŠããŸãã ãŸããå éšã¹ãã¬ãŒãžãŸãã¯å€éšã¹ãã¬ãŒãžã«æ ŒçŽãããŠãããã¡ã€ã«ãããåé¢ãããŠããŸãïŒåŸè ã¯ååšããªããããã€ã§ãæ¶ãã/衚瀺ãããå ŽåããããŸãïŒã
ãã¡ã€ã«ãæäœããããã®APIã¯ãã¢ã¯ãã£ããã£ã¯ã©ã¹ãšãµãŒãã¹ã¯ã©ã¹ã®æŽŸçå ã§ããContextã¯ã©ã¹ã«ãã£ãŠå®è£ ãããŸãã ãã®ã¯ã©ã¹ã«ã€ããŠã¯ããã§ã«ããã§èª¬æããŠããŸã ã
ä»æ¥ã¯ä»¥äžã§ãã 次ã®èšäºã§ã¯ãAndroidã¢ããªã±ãŒã·ã§ã³ã®ããŸããŸãªéšåãã©ã®ããã«çžäºäœçšãããã«ã€ããŠèª¬æããŸãã
åã®èšäºïŒ
- Androidã¢ããªã±ãŒã·ã§ã³ã¢ãŒããã¯ãã£ã ããŒãI-èµ·æº
- Androidã¢ããªã±ãŒã·ã§ã³ã¢ãŒããã¯ãã£ã ããŒãII-建ç¯ã¹ã¿ã€ã«ãšãã¿ãŒã³
次ã®èšäºïŒ Android Application Architectureã ããŒãIV-çµ±åã¬ãã«