SlideShare a Scribd company logo
おいしいFragment
           31.3.2012
Takahiro Yoshimura (@alterakey)
自己紹介

こんな人

 埼玉で活動しているアーキテクトです。

 FlashゲームからWebアプリまで。

 Twitterやってます→@alterakey
さて


Fragmentと聞いて

 何を思い浮べますか?

 何に使えるものなのでしょう?
Fragment?

Fragmentとは断片と見つけたり

Activityを機能的に分解する方法

大画面対応だけじゃない!

Android 1.6∼で使えます
大事なことなので


Android 1.6∼で使えます。

Support Package
簡単な例


Activityから他のアプリを呼び出しましょう。

Activity.startActivityForResult()

Activity.onActivityResult()
指針

MainActivity.java(抜粋)

public void onCreate(...) {
    ...
    this.startActivityForResult(intent, REQ_1);
    ...
}
...
public void onActivityResult(int requestCode, ...) {
    if (requestCode == REQ_1) {
        ...
    }
    ...
}
もしもこれが

Activity.startActivityForResult()を複数箇所で
呼び出していたら…?

Activityがもっと複雑だったら…?

カオス!!
指針


見通しを確保するために…

Activityから機能を分離します。

 REQ_1にまつわる部分
指針

MainActivity.java(抜粋)

public class MainActivity extends FragmentActivity {
...
    public void onCreate(...) {
      ...
      getSupportFragmentManager()
          .beginTransaction()
          .add(new RequestOneFragment(), null)
          .commit();
      ...
    }
...
指針

MainActivity.java(抜粋)

...
private class RequestOneFragment extends Fragment {
    private static final int REQ = 1;
    @Override
    public void onCreate(...) {
      super.onCreate(...);
      this.startActivityForResult(intent, REQ);
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, ...) {
      ...
    }
}
こうすると

「機能」ごとにまとまってすっきりする

同じようなことをしたい時に使い回しが効く
→機能を抽出しているので当然といえば当然…

状態を保存するのにも使える

しかし自動テストの役には立ちにくい…
大画面対応と聞くけど


ActivityからFragmentとしてUIを分離

条件に合わせてレイアウトを読んで、
Fragmentをはめこんで行けば…
(e.g. 狭ければ別Activity、広ければペイン)
まとめ

FragmentはActivityの持つ「機能」のこと

ペイン型UIやタブレットは関係ない

今からでも使える

しかし自動テストの役にはあまり立たない
まとめ

gdgdになりがちだったActivity周辺の見通し確
保にも有効

再利用もできる

ガンガン使おう!
ご静聴ありがとうございました。

More Related Content

Viewers also liked

アプリを弄ってみる #3 #antama_ws
アプリを弄ってみる #3 #antama_wsアプリを弄ってみる #3 #antama_ws
アプリを弄ってみる #3 #antama_ws
Takahiro Yoshimura
 
アプリを弄ってみる #2 #antama_ws
アプリを弄ってみる #2 #antama_wsアプリを弄ってみる #2 #antama_ws
アプリを弄ってみる #2 #antama_ws
Takahiro Yoshimura
 

Viewers also liked (14)

Viagra-ranking-report
Viagra-ranking-reportViagra-ranking-report
Viagra-ranking-report
 
伝授の巻について #スクエアフリーセミナー #yochiand
伝授の巻について #スクエアフリーセミナー #yochiand伝授の巻について #スクエアフリーセミナー #yochiand
伝授の巻について #スクエアフリーセミナー #yochiand
 
アプリを弄ってみる #3 #antama_ws
アプリを弄ってみる #3 #antama_wsアプリを弄ってみる #3 #antama_ws
アプリを弄ってみる #3 #antama_ws
 
Strategies for class
Strategies for classStrategies for class
Strategies for class
 
serp-iq-buy-viagra-ranking-report
serp-iq-buy-viagra-ranking-reportserp-iq-buy-viagra-ranking-report
serp-iq-buy-viagra-ranking-report
 
アプリを弄ってみる #1 #antama_ws
アプリを弄ってみる #1 #antama_wsアプリを弄ってみる #1 #antama_ws
アプリを弄ってみる #1 #antama_ws
 
参考書選びと迷った時の勉強法。 #antama_ws
参考書選びと迷った時の勉強法。 #antama_ws参考書選びと迷った時の勉強法。 #antama_ws
参考書選びと迷った時の勉強法。 #antama_ws
 
Eco Shift Power Corp. Overview
Eco Shift Power Corp. OverviewEco Shift Power Corp. Overview
Eco Shift Power Corp. Overview
 
アプリを弄ってみる #2 #antama_ws
アプリを弄ってみる #2 #antama_wsアプリを弄ってみる #2 #antama_ws
アプリを弄ってみる #2 #antama_ws
 
serp-iq-life-insurance-ranking-report
serp-iq-life-insurance-ranking-reportserp-iq-life-insurance-ranking-report
serp-iq-life-insurance-ranking-report
 
CLAS PLUACLD071 Evaluation
CLAS PLUACLD071 EvaluationCLAS PLUACLD071 Evaluation
CLAS PLUACLD071 Evaluation
 
LESION LIGAMENTO CRUZADO ANTERIOR
LESION LIGAMENTO CRUZADO ANTERIORLESION LIGAMENTO CRUZADO ANTERIOR
LESION LIGAMENTO CRUZADO ANTERIOR
 
Fracturas e inmovilizaciones
Fracturas e inmovilizacionesFracturas e inmovilizaciones
Fracturas e inmovilizaciones
 
Enfermedad de charcot marie tooth
Enfermedad de charcot marie toothEnfermedad de charcot marie tooth
Enfermedad de charcot marie tooth
 

Similar to おいしいFragment #antama_ws

ちょっと詳しくJavaScript 特別編【悪霊の神々】
ちょっと詳しくJavaScript 特別編【悪霊の神々】ちょっと詳しくJavaScript 特別編【悪霊の神々】
ちょっと詳しくJavaScript 特別編【悪霊の神々】
株式会社ランチェスター
 
goog.ui.Component のはぐれかた
goog.ui.Component のはぐれかたgoog.ui.Component のはぐれかた
goog.ui.Component のはぐれかた
Soichi Takamura
 
Node.js - JavaScript Thread Programming
Node.js - JavaScript Thread ProgrammingNode.js - JavaScript Thread Programming
Node.js - JavaScript Thread Programming
takesako
 
第三回ありえる社内勉強会 「いわががのLombok」
第三回ありえる社内勉強会 「いわががのLombok」第三回ありえる社内勉強会 「いわががのLombok」
第三回ありえる社内勉強会 「いわががのLombok」
yoshiaki iwanaga
 
Androidの通信周りのコーディングについて
Androidの通信周りのコーディングについてAndroidの通信周りのコーディングについて
Androidの通信周りのコーディングについて
Shoichi Takagi
 

Similar to おいしいFragment #antama_ws (20)

Tokyo GTUG Bootcamp2010
Tokyo GTUG Bootcamp2010Tokyo GTUG Bootcamp2010
Tokyo GTUG Bootcamp2010
 
GroovyなAndroidテスト #atest_hack
GroovyなAndroidテスト #atest_hackGroovyなAndroidテスト #atest_hack
GroovyなAndroidテスト #atest_hack
 
GDG DevFest 2020 Android data linkage info
GDG DevFest 2020 Android data linkage infoGDG DevFest 2020 Android data linkage info
GDG DevFest 2020 Android data linkage info
 
ちょっと詳しくJavaScript 特別編【悪霊の神々】
ちょっと詳しくJavaScript 特別編【悪霊の神々】ちょっと詳しくJavaScript 特別編【悪霊の神々】
ちょっと詳しくJavaScript 特別編【悪霊の神々】
 
AsyncTask アンチパターン
AsyncTask アンチパターンAsyncTask アンチパターン
AsyncTask アンチパターン
 
goog.ui.Component のはぐれかた
goog.ui.Component のはぐれかたgoog.ui.Component のはぐれかた
goog.ui.Component のはぐれかた
 
Using the Fragments(Android)
Using the Fragments(Android)Using the Fragments(Android)
Using the Fragments(Android)
 
About Jobs
About JobsAbout Jobs
About Jobs
 
Build your AR app by using AR Foundation samples
Build your AR app by using AR Foundation samplesBuild your AR app by using AR Foundation samples
Build your AR app by using AR Foundation samples
 
Node.js - JavaScript Thread Programming
Node.js - JavaScript Thread ProgrammingNode.js - JavaScript Thread Programming
Node.js - JavaScript Thread Programming
 
Android4.2徹底解剖!
Android4.2徹底解剖!Android4.2徹底解剖!
Android4.2徹底解剖!
 
OnActivityResult - おまえら!もうonActivityResultでswitchとif書く時代は終わりだぞ!
OnActivityResult - おまえら!もうonActivityResultでswitchとif書く時代は終わりだぞ!OnActivityResult - おまえら!もうonActivityResultでswitchとif書く時代は終わりだぞ!
OnActivityResult - おまえら!もうonActivityResultでswitchとif書く時代は終わりだぞ!
 
Twitter sphere of #twitter4j #twtr_hack
Twitter sphere of #twitter4j #twtr_hackTwitter sphere of #twitter4j #twtr_hack
Twitter sphere of #twitter4j #twtr_hack
 
第三回ありえる社内勉強会 「いわががのLombok」
第三回ありえる社内勉強会 「いわががのLombok」第三回ありえる社内勉強会 「いわががのLombok」
第三回ありえる社内勉強会 「いわががのLombok」
 
Androidの通信周りのコーディングについて
Androidの通信周りのコーディングについてAndroidの通信周りのコーディングについて
Androidの通信周りのコーディングについて
 
Ecmascript2015とその周辺について
Ecmascript2015とその周辺についてEcmascript2015とその周辺について
Ecmascript2015とその周辺について
 
Unit testing JavaScript with JUnit/JavaFX
Unit testing JavaScript with JUnit/JavaFXUnit testing JavaScript with JUnit/JavaFX
Unit testing JavaScript with JUnit/JavaFX
 
Android Lecture #03 @PRO&BSC Inc.
Android Lecture #03 @PRO&BSC Inc.Android Lecture #03 @PRO&BSC Inc.
Android Lecture #03 @PRO&BSC Inc.
 
Rx java x retrofit
Rx java x retrofitRx java x retrofit
Rx java x retrofit
 
JavaScript 実践講座 Framework, Tool, Performance
JavaScript 実践講座 Framework, Tool, PerformanceJavaScript 実践講座 Framework, Tool, Performance
JavaScript 実践講座 Framework, Tool, Performance
 

More from Takahiro Yoshimura

More from Takahiro Yoshimura (20)

Looking Back 2023
Looking Back 2023Looking Back 2023
Looking Back 2023
 
Fill In The Blank
Fill In The BlankFill In The Blank
Fill In The Blank
 
Ticket To The Dark World
Ticket To The Dark WorldTicket To The Dark World
Ticket To The Dark World
 
Looking back 2022
Looking back 2022Looking back 2022
Looking back 2022
 
Hazy Datagrams
Hazy DatagramsHazy Datagrams
Hazy Datagrams
 
Wartime Pigeons
Wartime PigeonsWartime Pigeons
Wartime Pigeons
 
Securing Supply Chains
Securing Supply ChainsSecuring Supply Chains
Securing Supply Chains
 
Looking Back: CIS on Managed K8S
Looking Back: CIS on Managed K8SLooking Back: CIS on Managed K8S
Looking Back: CIS on Managed K8S
 
Beijing Report 2022
Beijing Report 2022Beijing Report 2022
Beijing Report 2022
 
Asynchronicity
AsynchronicityAsynchronicity
Asynchronicity
 
Outsmarting Smartphone Apps 2
Outsmarting Smartphone Apps 2Outsmarting Smartphone Apps 2
Outsmarting Smartphone Apps 2
 
Outsmarting Smartphone Apps 2
Outsmarting Smartphone Apps 2Outsmarting Smartphone Apps 2
Outsmarting Smartphone Apps 2
 
Outsmarting Smartphone Apps
Outsmarting Smartphone AppsOutsmarting Smartphone Apps
Outsmarting Smartphone Apps
 
Drawing Dataflow On Dalvik Bytecodes
Drawing Dataflow On Dalvik Bytecodes Drawing Dataflow On Dalvik Bytecodes
Drawing Dataflow On Dalvik Bytecodes
 
Trueseeing: Effective Dataflow Analysis over Dalvik Opcodes
Trueseeing: Effective Dataflow Analysis over Dalvik OpcodesTrueseeing: Effective Dataflow Analysis over Dalvik Opcodes
Trueseeing: Effective Dataflow Analysis over Dalvik Opcodes
 
10 (about make 10 with 4 numbers challenge)
10 (about make 10 with 4 numbers challenge)10 (about make 10 with 4 numbers challenge)
10 (about make 10 with 4 numbers challenge)
 
Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile
Go goes Mobile: Quick Exploration on Go 1.5 and GomobileGo goes Mobile: Quick Exploration on Go 1.5 and Gomobile
Go goes Mobile: Quick Exploration on Go 1.5 and Gomobile
 
Android Wear: Good Parts
Android Wear: Good PartsAndroid Wear: Good Parts
Android Wear: Good Parts
 
DEFCON21×S2 REPORT
DEFCON21×S2 REPORTDEFCON21×S2 REPORT
DEFCON21×S2 REPORT
 
あげフォト開発ノート #antama_ws
あげフォト開発ノート #antama_wsあげフォト開発ノート #antama_ws
あげフォト開発ノート #antama_ws
 

Recently uploaded

2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
ssuserbefd24
 

Recently uploaded (10)

2024年度_サイバーエージェント_新卒研修「データベースの歴史」.pptx
2024年度_サイバーエージェント_新卒研修「データベースの歴史」.pptx2024年度_サイバーエージェント_新卒研修「データベースの歴史」.pptx
2024年度_サイバーエージェント_新卒研修「データベースの歴史」.pptx
 
MPAなWebフレームワーク、Astroの紹介 (その2) 2024/05/24の勉強会で発表されたものです。
MPAなWebフレームワーク、Astroの紹介 (その2) 2024/05/24の勉強会で発表されたものです。MPAなWebフレームワーク、Astroの紹介 (その2) 2024/05/24の勉強会で発表されたものです。
MPAなWebフレームワーク、Astroの紹介 (その2) 2024/05/24の勉強会で発表されたものです。
 
論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...
論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...
論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...
 
LoRaWAN 4チャンネル電流センサー・コンバーター CS01-LB 日本語マニュアル
LoRaWAN 4チャンネル電流センサー・コンバーター CS01-LB 日本語マニュアルLoRaWAN 4チャンネル電流センサー・コンバーター CS01-LB 日本語マニュアル
LoRaWAN 4チャンネル電流センサー・コンバーター CS01-LB 日本語マニュアル
 
20240523_IoTLT_vol111_kitazaki_v1___.pdf
20240523_IoTLT_vol111_kitazaki_v1___.pdf20240523_IoTLT_vol111_kitazaki_v1___.pdf
20240523_IoTLT_vol111_kitazaki_v1___.pdf
 
YugabyteDB適用に向けた取り組みと隠れた魅力 (DSS Asia 2024 発表資料)
YugabyteDB適用に向けた取り組みと隠れた魅力 (DSS Asia 2024 発表資料)YugabyteDB適用に向けた取り組みと隠れた魅力 (DSS Asia 2024 発表資料)
YugabyteDB適用に向けた取り組みと隠れた魅力 (DSS Asia 2024 発表資料)
 
【AI論文解説】Consistency ModelとRectified Flow
【AI論文解説】Consistency ModelとRectified Flow【AI論文解説】Consistency ModelとRectified Flow
【AI論文解説】Consistency ModelとRectified Flow
 
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
 
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
 
論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes
論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes
論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes
 

おいしいFragment #antama_ws

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n