Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
最新のFragment事情 / Fragment new features
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
star_zero
November 21, 2019
Programming
3.4k
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
最新のFragment事情 / Fragment new features
star_zero
November 21, 2019
More Decks by star_zero
See All by star_zero
今からはじめるAndroidアプリ開発 2024 / DevFest 2024
star_zero
0
1.7k
Jetpack Compose の Side-effect を使いこなす / DroidKaigi 2023
star_zero
5
7.3k
Android 14 新機能 / Android 14 Meetup Nagoya
star_zero
1
700
Android 14 と Predictive back gesture / Shibuya.apk #42
star_zero
0
520
Coroutines Test 入門 / Android Test Night #8
star_zero
2
1.4k
What's new in Jetpack / I/O Extended Japan 2022
star_zero
1
730
Kotlin 2021 Recap / DevFest 2021
star_zero
3
1.4k
Kotlin Symbol Processing (KSP) を使ったコード生成 / DroidKaigi 2021
star_zero
2
5.3k
What's new Android 12
star_zero
0
640
Other Decks in Programming
See All in Programming
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
330
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
170
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
210
Seven New Principles of Software Engineering
yegor256
0
270
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
200
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
370
最近”作らせてる” ローカルAIアプリの話
akit37
0
490
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
1.2k
dotNET_vulnclicker_intro.pdf
deka_morita
0
150
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
200
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
160
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
1.3k
Featured
See All Featured
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
A Tale of Four Properties
chriscoyier
163
24k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
540
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
810
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.8k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
860
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Transcript
最新のFragment事情 Android感謝祭 2019/11/21
About me •Kenji Abe •クックパッド株式会社 •Google Developers Expert for Android
•Twitter: @STAR_ZERO
Update Fragment
⚠今回の環境⚠ •Fragment 1.2.0 rc-02 ‣ 2019/11/21時点の最新
Constructor with LayoutId
Constructor with LayoutId •コンストラクタにLayoutIdを渡せるようになった •DataBinding/ViewBindingは非対応 class SampleFragment : Fragment(R.layout.fragment_sample)
Constructor with LayoutId https://developer.android.com/reference/androidx/fragment/app/Fragment.html
FragmentContainerView
FragmentContainerView •これからはFrameLayoutではなくコチラが推奨 •アニメーションのz-orderなどのバグがあった •https://issuetracker.google.com/issues/37036000
FragmentContainerView <androidx.fragment.app.FragmentContainerView android:id="@+id/container" android:name="com.example.SampleFragment" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"
/>
OnBackPressedDispatcher
OnBackPressedDispatcher •Fragmentでバックキーの制御が可能になった •Lifecycleによってコールバックの追加、削除が簡単 •コールバックの有効、無効の切り替えも可能
OnBackPressedDispatcher class SampleFragment : Fragment() { private val callback =
object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { // バックキーが押されたとき... } } override fun onAttach(context: Context) { super.onAttach(context) requireActivity().onBackPressedDispatcher .addCallback(this, callback) } }
OnBackPressedDispatcher class SampleFragment : Fragment() { // ... fun someFunction()
{ callback.isEnabled = false requireActivity().onBackPressedDispatcher.onBackPressed() } }
OnBackPressedDispatcher class MainActivity : AppCompatActivity() { override fun onBackPressed() {
// FragmentのhandleOnBackPressedの後に呼び出される if (onBackPressedDispatcher.hasEnabledCallbacks()) { // Fragmentのバックキー制御が有効 } else { // Fragmentのバックキー制御が無効 } } }
FragmentFactory
FragmentFactory •Fragmentの生成を行うクラス •Fragmentのコンストラクタに引数が渡せるようになる ‣ コンストラクタインジェクションが可能 •引数なしのコンストラクタ不要 •FragmentScenarioでMock
FragmentFactory class SampleFactory: FragmentFactory() { override fun instantiate( classLoader: ClassLoader,
className: String ): Fragment { return when (className) { SampleFragment::class.java.name -> SampleFragment("ABC") else -> super.instantiate(classLoader, className) } } }
FragmentFactory class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?)
{ supportFragmentManager.fragmentFactory = SampleFactory() super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // fragment-ktx supportFragmentManager.commit { add<SampleFragment>(R.id.container) } } }
FragmentFactory @RunWith(AndroidJUnit4::class) class SampleFragmentTest { @Test fun textSample() { val
mockFactory = MockFactory() val scenario = launchFragmentInContainer<SampleFragment>( factory = mockFactory ) onView(withId(R.id.text)).check(matches(withText("Hello World!"))) } }
FragmentFactory •Daggerで使うには? ‣ https://satoshun.github.io/2018/11/android_all_inject_ctor/
RESUME_ONLY_CURRENT_FRAGMENT
RESUME_ONLY_CURRENT_FRAGMENT •ViewPagerでonResumeが呼ばれるタイミングが変わる ‣ これまでは表示されてなくてもonResumeが呼ばれてた ‣ 表示されてるFragmentのonResumeのみが呼ばれる •setUserVisibleHintはDeprecated
RESUME_ONLY_CURRENT_FRAGMENT class SampleAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { // 以前の挙動にしたい場合は
BEHAVIOR_SET_USER_VISIBLE_HINT override fun getItem(position: Int): Fragment { // ... } override fun getCount(): Int { // ... } }
fragment-ktx
fragment-ktx supportFragmentManager.commit { add<SampleFragment>(R.id.container) } val viewModel: SampleViewModel by viewModels()
val viewModel: SampleViewModel by activityViewModels() val viewModel: SampleViewModel by viewModels { viewModelFactory }
lint
lint
lint
今後のFragment
今後のFragment https://www.youtube.com/watch?v=RS1IACnZLy4
今後のFragment •Multiple Back Stacks •Fragmentの戻り値 •Lifecycleの改善
ありがとうございました