Submit Search
Upload
Potato04 The end of confusion of callback between activity and fragment.
•
6 likes
•
2,550 views
Toshihiro Yagi
Follow
The end of confusion of callback between activity and fragment.
Read less
Read more
Report
Share
Report
Share
1 of 21
Download now
Download to read offline
Recommended
JUnit 5
JUnit 5
Kostadin Golev
OCP kata overview
OCP kata overview
Kevin Rutherford
Introduction to ReactJS
Introduction to ReactJS
Daine Mawer
Test code that will not slow you down
Test code that will not slow you down
Kostadin Golev
JUnit 5 Extensions
JUnit 5 Extensions
Marc Philipp
Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018
Hazem Saleh
What is new in JUnit5
What is new in JUnit5
Richard Langlois P. Eng.
JUnit 5 - The Next Generation
JUnit 5 - The Next Generation
Kostadin Golev
Recommended
JUnit 5
JUnit 5
Kostadin Golev
OCP kata overview
OCP kata overview
Kevin Rutherford
Introduction to ReactJS
Introduction to ReactJS
Daine Mawer
Test code that will not slow you down
Test code that will not slow you down
Kostadin Golev
JUnit 5 Extensions
JUnit 5 Extensions
Marc Philipp
Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018
Hazem Saleh
What is new in JUnit5
What is new in JUnit5
Richard Langlois P. Eng.
JUnit 5 - The Next Generation
JUnit 5 - The Next Generation
Kostadin Golev
iOS Unit Testing
iOS Unit Testing
sgleadow
Unit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava Talk
Long Weekend LLC
Android Test Pyramid - Ágiles 2013
Android Test Pyramid - Ágiles 2013
Rafael Portela
From DevOps to GitOps with GitLab
From DevOps to GitOps with GitLab
Chen Cheng-Wei
Unit Testing in iOS
Unit Testing in iOS
Long Weekend LLC
Programming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStrings
Alan Richardson
Interpreter RPG to Java
Interpreter RPG to Java
farerobe
Unit Testing RPG with JUnit
Unit Testing RPG with JUnit
Greg.Helton
Abc2011 2 yagi
Abc2011 2 yagi
Toshihiro Yagi
Flight入門
Flight入門
Toshihiro Yagi
Abc2011 yagi
Abc2011 yagi
Toshihiro Yagi
Potato02 ViewSticker作りました
Potato02 ViewSticker作りました
Toshihiro Yagi
Potato01 No more 手書き ViewHolder
Potato01 No more 手書き ViewHolder
Toshihiro Yagi
Potato03 KotlinでAndroidアプリ開発(後編)
Potato03 KotlinでAndroidアプリ開発(後編)
Toshihiro Yagi
Re viewのリアルタイムプレギュー機能をつくってみたよ
Re viewのリアルタイムプレギュー機能をつくってみたよ
Toshihiro Yagi
Firefox osでlineは作れるか
Firefox osでlineは作れるか
Toshihiro Yagi
深入淺出談Fragment
深入淺出談Fragment
毅 方
2. Design patterns. part #2
2. Design patterns. part #2
Leonid Maslov
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
Giorgio Sironi
Android best practices
Android best practices
Jose Manuel Ortega Candel
Droidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offline
Javier de Pedro López
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
ppd1961
More Related Content
What's hot
iOS Unit Testing
iOS Unit Testing
sgleadow
Unit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava Talk
Long Weekend LLC
Android Test Pyramid - Ágiles 2013
Android Test Pyramid - Ágiles 2013
Rafael Portela
From DevOps to GitOps with GitLab
From DevOps to GitOps with GitLab
Chen Cheng-Wei
Unit Testing in iOS
Unit Testing in iOS
Long Weekend LLC
Programming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStrings
Alan Richardson
Interpreter RPG to Java
Interpreter RPG to Java
farerobe
Unit Testing RPG with JUnit
Unit Testing RPG with JUnit
Greg.Helton
What's hot
(8)
iOS Unit Testing
iOS Unit Testing
Unit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava Talk
Android Test Pyramid - Ágiles 2013
Android Test Pyramid - Ágiles 2013
From DevOps to GitOps with GitLab
From DevOps to GitOps with GitLab
Unit Testing in iOS
Unit Testing in iOS
Programming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStrings
Interpreter RPG to Java
Interpreter RPG to Java
Unit Testing RPG with JUnit
Unit Testing RPG with JUnit
Viewers also liked
Abc2011 2 yagi
Abc2011 2 yagi
Toshihiro Yagi
Flight入門
Flight入門
Toshihiro Yagi
Abc2011 yagi
Abc2011 yagi
Toshihiro Yagi
Potato02 ViewSticker作りました
Potato02 ViewSticker作りました
Toshihiro Yagi
Potato01 No more 手書き ViewHolder
Potato01 No more 手書き ViewHolder
Toshihiro Yagi
Potato03 KotlinでAndroidアプリ開発(後編)
Potato03 KotlinでAndroidアプリ開発(後編)
Toshihiro Yagi
Re viewのリアルタイムプレギュー機能をつくってみたよ
Re viewのリアルタイムプレギュー機能をつくってみたよ
Toshihiro Yagi
Firefox osでlineは作れるか
Firefox osでlineは作れるか
Toshihiro Yagi
Viewers also liked
(8)
Abc2011 2 yagi
Abc2011 2 yagi
Flight入門
Flight入門
Abc2011 yagi
Abc2011 yagi
Potato02 ViewSticker作りました
Potato02 ViewSticker作りました
Potato01 No more 手書き ViewHolder
Potato01 No more 手書き ViewHolder
Potato03 KotlinでAndroidアプリ開発(後編)
Potato03 KotlinでAndroidアプリ開発(後編)
Re viewのリアルタイムプレギュー機能をつくってみたよ
Re viewのリアルタイムプレギュー機能をつくってみたよ
Firefox osでlineは作れるか
Firefox osでlineは作れるか
Similar to Potato04 The end of confusion of callback between activity and fragment.
深入淺出談Fragment
深入淺出談Fragment
毅 方
2. Design patterns. part #2
2. Design patterns. part #2
Leonid Maslov
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
Giorgio Sironi
Android best practices
Android best practices
Jose Manuel Ortega Candel
Droidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offline
Javier de Pedro López
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
ppd1961
Встреча Google Post IO ( Владимир Иванов, Катерина Заворотченко и Сергей Комлач)
Встреча Google Post IO ( Владимир Иванов, Катерина Заворотченко и Сергей Комлач)
Alina Vilk
Performance #6 threading
Performance #6 threading
Vitali Pekelis
Lecture #4 activities & fragments
Lecture #4 activities & fragments
Vitali Pekelis
Testing of javacript
Testing of javacript
Lei Kang
Agile mobile
Agile mobile
Godfrey Nolan
JavaFX8 TestFX - CDI
JavaFX8 TestFX - CDI
Sven Ruppert
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
Gabor Varadi
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Naresh Jain
Dot Net Accenture
Dot Net Accenture
Sri K
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Mario Fusco
How to code to code less
How to code to code less
Anton Novikau
Dave Karow, Split. Powering Progressive Delivery With Data
Dave Karow, Split. Powering Progressive Delivery With Data
IT Arena
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
Oliver Gierke
What the fragments
What the fragments
Gowtham Kumar
Similar to Potato04 The end of confusion of callback between activity and fragment.
(20)
深入淺出談Fragment
深入淺出談Fragment
2. Design patterns. part #2
2. Design patterns. part #2
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
Android best practices
Android best practices
Droidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offline
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
Встреча Google Post IO ( Владимир Иванов, Катерина Заворотченко и Сергей Комлач)
Встреча Google Post IO ( Владимир Иванов, Катерина Заворотченко и Сергей Комлач)
Performance #6 threading
Performance #6 threading
Lecture #4 activities & fragments
Lecture #4 activities & fragments
Testing of javacript
Testing of javacript
Agile mobile
Agile mobile
JavaFX8 TestFX - CDI
JavaFX8 TestFX - CDI
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Dot Net Accenture
Dot Net Accenture
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
How to code to code less
How to code to code less
Dave Karow, Split. Powering Progressive Delivery With Data
Dave Karow, Split. Powering Progressive Delivery With Data
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
What the fragments
What the fragments
Potato04 The end of confusion of callback between activity and fragment.
1.
The end of confusion
of callback between activity and fragment. 2014-02-12 potatotips #4 Toshihiro Yagi
2.
About me Twitter :
@sys1yagi Blog : http://sys1yagi.com ! ! Android Engineer at
3.
出てます。 http://www.amazon.co.jp/gp/product/4798040029/
4.
Problem • How communicate between
Activity and Fragment? ? Activity Fragment
5.
#01 Implement a
interface in a Activity Implements Interface Declare Interface @Override public void onAttach(Activity activity) { super.onAttach(activity); try { mCallback = (Listener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement Listener"); } } Communicating with Other Fragments http://developer.android.com/training/basics/fragments/communicating.html
6.
mCallback = (Listener)
activity; throw new いいんだけどダサくね? try{}catch{} ClassCastExcep ends Activity implements Listener{
7.
#02 No rotation
or receive config changes. Declare Interface No rotation Set Interface
8.
でも結局Activity破棄再生成で死ぬよね?
9.
#03 Using message
bus. Message Bus Otto ! @Override protected void onCreate(Bundle save) { super.onCreate(savedInstanceState); bus.register(this); } @Subscribe private void onClick(OnClickEvent event){ //do something } bus.post(new OnClickEvent(10)); Otto http://square.github.io/otto/
10.
濫用するときつい コンテキスト遠い
11.
#04 Using Roboguice
or Dagger, etc… Injector Module Depend on Declare Interface
12.
OK but, exaggerated
13.
In the first
place… • なんでActivity-Fragment間連携の為に色々な罠を かいくぐらなければならないんだ • ついでにDialogFragment-Fragment間もだるい • 再生成を別々にするのがそもそもおかしくね? • 基本的にActivity←Fragmentの一方向依存だよね • 統一的で簡単で罠のない書き方がほしい
14.
無かったら作る
15.
indirect injector
16.
Simplify Indirect Injector Declare Interface add
dependency inject request
17.
Simplify Indirect Injector Declare Interface add
dependency inject request @Override protected void onCreate(Bundle save) { super.onCreate(savedInstanceState); IndirectInjector.addDependency(this, mListener); } @Inject Listener mListener; ! @Override public void onActivityCreated(Bundle savedInstanceState) { IndirectInjector.inject(getActivity(), this); }
18.
Good bye confusion • build.gradleにdependencies書いて • Fragmentの必要なフィールドに@Injectつけて • Activity側でIndirectInjectorにaddDependency()する • FragmentのonActivityCreated()でIndirectInjectorの inject()を呼ぶ • どういう再生成が走っても大丈夫
19.
Enjoy!
20.
おわりに https://github.com/sys1yagi/indirect-injector Welcome your pull
request! GitHub活動を通して個人のキャリアを積みつつ仕事の成果を出したい
21.
We are hiring!!!
Download now