Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Android Lifecycle再復習 / Review the Android Lifec...
Search
Yasutaka Kawamoto
September 28, 2019
Programming
0
300
Android Lifecycle再復習 / Review the Android Lifecycle callback methods again
Android研究&発表会#1で発表した資料です!
https://arap.connpass.com/event/146619/
Yasutaka Kawamoto
September 28, 2019
Tweet
Share
More Decks by Yasutaka Kawamoto
See All by Yasutaka Kawamoto
GraphQLを使ってアプリを作っている話 / The story of building an app using GraphQL
yasi
2
700
Flutter製チャットアプリを支える技術 / Technologies that support a Flutter chat application
yasi
1
770
Combine CameraX and MLKit
yasi
1
170
Android Architecture ComponentのLifecyle対応コンポーネントのおさらい / Review of Lifecyle aware components of AAC
yasi
0
360
Retrofit2の仕組み 〜CallAdapterを理解する〜 / How Retrofit2 works ~ Understand CallAdapter ~
yasi
0
610
Retrofit2の仕組み 〜オリジナルConverterを作ってみる〜 / How Retrofit2 works ~ Try making your own Converter ~
yasi
0
510
アプリ内課金 プラグインの現状 / Present situation of in-app purchase in Flutter
yasi
6
2.3k
AndroidやiOSのアプリ開発でいつも私がやっていることをFlutterでやってみた / Flutter development as usual
yasi
3
1.7k
Intro to Flutter
yasi
0
760
Other Decks in Programming
See All in Programming
Better Code Design in PHP
afilina
PRO
0
120
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
EventSourcingの理想と現実
wenas
6
2.3k
Realtime API 入門
riofujimon
0
150
Contemporary Test Cases
maaretp
0
130
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1k
Jakarta EE meets AI
ivargrimstad
0
580
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
Jakarta EE meets AI
ivargrimstad
0
510
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Embracing the Ebb and Flow
colly
84
4.5k
Visualization
eitanlees
145
15k
A Tale of Four Properties
chriscoyier
156
23k
What's in a price? How to price your products and services
michaelherold
243
12k
Designing for Performance
lara
604
68k
GraphQLとの向き合い方2022年版
quramy
43
13k
BBQ
matthewcrist
85
9.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Transcript
Android Lifecycle࠶෮श Androidݚڀ&ൃදձ #1 2019/09/28 1
• Տຊ ହ(͔Θͱ ͔ͨ͢) • ॴଐɿגࣜձࣾ tech vein (େࡕࢢதԝ۠ຊொ)
• ϞόΠϧΞϓϦΤϯδχΞ (AndroidଟΊɺiOSŧŔŕŪũƄŝſ) • GitHub: kwmt ɺtwitter: kwmt27 • Google I/O2018 ॳࢀՃ • Ԭग़ • ΫϥϑτϏʔϧ͖ 2 ࣗݾհ
3 ࠷ۙݸਓͰϦϦʔεͨ͠AndroidΞϓϦ https://play.google.com/store/apps/details?id=net.kwmt27.qrcode_reader
AndroidͷϥΠϑαΠΫϧ ͪΌΜͱཧղͯ͠·͔͢ʁ 4
5
5
5
ཧղͨ͠ؾʹͳ͍ͬͯ·ͤΜ͔ʁ 6
ཧղͨ͠ؾʹͳ͍ͬͯ·ͨ͆͠ 7
ϥΠϑαΠΫϧʹ͍ͭͯ෮श͍ͨ͠ͱࢥ͍·͢ɻ 8
9 ΞδΣϯμ • ϥΠϑαΠΫϧͱʁ • ϥΠϑαΠΫϧͷ֤ίʔϧόοΫͷ υΩϡϝϯτΛ֬ೝ͢Δ • ײ
10 ಈ࡞֬ೝ • Android 10 • LaunchMode = Default
11 ϥΠϑαΠΫϧͱʁ • AndroidΞϓϦ͕ىಈ͔ͯ͠Βऴྃ͢Δ·ͰΛϥΠϑαΠ Ϋϧͱͯ͠ఆ͍ٛͯ͠·͢ɻ • ىಈɾऴྃͪΖΜɺதஅ࠶ىಈͳͲؚ·Ε· ͢ɻ • ͜ΕΒAndroidϑϨʔϜϫʔΫ͔ΒͷίʔϧόοΫͱ͠
ͯΔ͜ͱ͕Ͱ͖·͢ɻ • ͨͱ͑ɺΞϓϦىಈ࣌ͷίʔϧόοΫonCreateɺऴ ྃ࣌onDestoryͳͲͰ͢ɻ
12 ϥΠϑαΠΫϧͱʁ • AndroidʹActivityFragmentͷଞʹServiceͳͲͷίϯ ϙʔωϯτຖʹϥΠϑαΠΫϧ͕نఆ͞Ε͍ͯ·͢ɻ • ࠓճओʹActivityͱFragmentͷϥΠϑαΠΫϧʹ͍ͭ ͯΈ͍͖͍ͯͨͱࢥ͍·͢ɻ
13 ఆΞϓϦ • 1ͭͷActivity • 2ͭͷFragment͕͋Δ • Activityʹ͋ΔϘλϯ(FAB)ΛΫϦοΫ͢Δͱɺ2ͭͷը ໘ʹભҠ͢Δ͜ͱ͕Ͱ͖Δ •
ભҠઌͷFragment͔ΒόοΫΩʔͰભҠݩͷFragmentʹ Δ͜ͱ͕Ͱ͖Δ
14
14
͜ͷΞϓϦ͕ ىಈ͢Δͱ͖ͱऴྃ͢Δͱ͖ɺ ͲͷΑ͏ͳίʔϧόοΫ͕ ݺͼग़͞ΕΔ͔֬ೝ͍ͨ͠ͱࢥ͍·͢ɻ 15
16 ΞϓϦىಈ࣌ͷΠϝʔδ
16 ΞϓϦىಈ࣌ͷΠϝʔδ
ΞϓϦىಈ࣌ͷϥΠϑαΠΫϧ Activity Fragment ࣌ؒ
ΞϓϦىಈ࣌ͷϥΠϑαΠΫϧ onCreate Activity Fragment ࣌ؒ
ΞϓϦىಈ࣌ͷϥΠϑαΠΫϧ onCreate onAttach onCreate onCreateView onActivityCreated onViewStateRestored onStart Activity Fragment
࣌ؒ
ΞϓϦىಈ࣌ͷϥΠϑαΠΫϧ onCreate onAttach onCreate onCreateView onActivityCreated onViewStateRestored onStart onResume onStart
Activity Fragment ࣌ؒ
ΞϓϦىಈ࣌ͷϥΠϑαΠΫϧ onCreate onAttach onResume onCreate onCreateView onActivityCreated onViewStateRestored onStart onResume
onStart Activity Fragment ࣌ؒ
18 ΞϓϦऴྃ࣌ͷΠϝʔδ
18 ΞϓϦऴྃ࣌ͷΠϝʔδ
19 ΞϓϦऴྃ࣌ͷϥΠϑαΠΫϧ Activity Fragment ࣌ؒ ※super.onHogeͷޙͷλΠϛϯάͰ֬ೝ
19 ΞϓϦऴྃ࣌ͷϥΠϑαΠΫϧ onPause onPause onStop Activity Fragment onStop onDestroy onDestroyView
onDestroy onDetach ࣌ؒ ※super.onHogeͷޙͷλΠϛϯάͰ֬ೝ
֤ίʔϧόοΫͷυΩϡϝϯτΛ֬ೝ 20
• Activity͕։࢝͢Δͱ͖ʹݺΕΔϝιουͰ͢ɻ ͜͜΄ͱΜͲͷॳظԽॲཧΛߦ͏ॴͰ͢ɻ • setContentViewΛݺΜͰActivityͷUIΛΠϯϑϨʔτ ͨ͠ΓɺfindViewByIdΛ֤ͬͯViewͷηοτΞοϓ ͨ͠Γɺදࣔ͢ΔͨΊͷσʔλΛऔಘͨ͠Γ͠·͢ɻ • onCreateͰfinishΛݺͿ͜ͱͰ͖·͢ɻ ͦͷ߹ɺonCreateޙ͙͢ʹonDestroy͕ݺΕɺ
onStart, onResume, onPause, onStopݺΕ·ͤ Μɻ onCreate 21
22 onCreateͰfinishΛݺΜͩ߹ Activity Fragment ࣌ؒ
22 onCreateͰfinishΛݺΜͩ߹ onCreate Activity Fragment ࣌ؒ ͜͜Ͱfinish()Λίʔϧ
22 onCreateͰfinishΛݺΜͩ߹ onAttach onCreate onCreate Activity Fragment onDestroy onDestroy onDetach
࣌ؒ ͜͜Ͱfinish()Λίʔϧ
• ϑϥάϝϯτ͕ͦͷίϯςΩετʹ࠷ॳʹΞλον͞ ΕΔͱ͖ʹݺͼग़͞Ε·͢ɻ ͜ͷޙɺonCreate͕ݺͼग़͞Ε·͢ɻ onCreate onAttach 23
• Fragmentͷ࡞࣌ʹݺΕ·͢ɻ onAttachͷޙͰonCreateViewͷલʹݺΕ·͢ɻ • Fragment͕ଐ͍ͯ͠Δactivity͕࡞தʹݺͼग़͞Ε ΔͷͰɺactivityͷViewΛࢀরͰ͖·ͤΜɻ • ActivityͷViewΛࢀর͢ΔͷɺonActivityCreatedͰ ߦ͍ͬͯͩ͘͞ɻ onCreate
onCreate 24
• ϑϥάϝϯτʹϢʔβʔΠϯλʔϑΣΠεϏϡʔΛΠϯελϯε Խͤ͞ΔͨΊʹݺͼग़͞Ε·͢ɻ ͜ΕΦϓγϣϯͰ͋Γɺඇά ϥϑΟΧϧϑϥάϝϯτnullΛฦ͢Մೳੑ͕͋Γ·͢ɻ ͜Ε ɺonCreateͱonActivityCreatedͷؒͰݺͼग़͞Ε·͢ɻ • ίϯετϥΫλFragment(int)Λݺͼग़͢ͱɺσϑΥϧτϏϡʔ ͕ฦ͞Ε·͢ɻ
ͦΕҎ֎ͷ߹ɺ͜ͷϝιουnullΛฦ͠· ͢ɻ • ͜ͷϝιουͰͷΈϨΠΞτΛల։͠ɺฦ͞ΕͨϏϡʔͰಈ࡞ ͢ΔϩδοΫΛonViewCreatedʹҠಈ͢Δ͜ͱΛ͓קΊ͠·͢ɻ • ͔͜͜ΒϏϡʔΛฦ͢߹ɺޙͰϏϡʔ͕ղ์͞ΕΔͱ͖ʹ onDestroyViewͰݺͼग़͞Ε·͢ɻ onCreate onCreateView 25
26 ίϯετϥΫλFragment(int) • Fragmentʹlayout idΛͤΔίϯετϥΫλ • class MyFragment: Fragment(R.layout.fragment_my) {}
ͱॻ͚·͢ • onCreateViewΛΦʔόʔϥΠυͯ͠ɺinflateͨ͠ViewΛ ฦ͞ͳ͍͍ͯ͘(ϑϨʔϜϫʔΫଆͰͬͯ͘ΕΔ)
27 ίϯετϥΫλFragment(int) • JetpackͷfragmentϥΠϒϥϦͷมߋΛݟΔͱ
28 ίϯετϥΫλFragment(int) • 20199݄5όʔδϣϯ1.1.0ͰՃ͞ΕͨͷͷΑ͏Ͱ ͢ɻ • ͨͩɺ͍·ͰDatabindingΛ͏͜ͱ͕ଟ͍͔͠Ε· ͤΜͷͰɺͦͷ߹͍··Ͱ௨ΓonCreateViewͰ ViewΛฦ͢͜ͱʹͳΔ͔ͱࢥ͍·͢ɻ
• FragmentͷActivity͕࡞ྃ͠ɺFragmentͷView֊ ͕ΠϯελϯεԽ͞Εͨͱ͖ʹݺΕ·͢ɻϏϡʔ ͷऔಘঢ়ଶͷ෮ݩͳͲɺ͜ΕΒͷཁૉ͕ஔ͞Εͨ ޙɺ࠷ऴతͳॳظԽΛߦ͏ͨΊʹ༻Ͱ͖·͢ɻ • onCreateViewͷޙʹݺΕ·͢ɻ onViewStateRestoredͷલʹݺΕ·͢ɻ onCreate onActivityCreated
29
• อଘ͞Εͨͯ͢ͷঢ়ଶ͕ϑϥάϝϯτͷϏϡʔ֊ ʹ෮ݩ͞Εͨͱ͖ʹݺͼग़͞Ε·͢ɻ • ͜ΕɺνΣοΫϘοΫεΟδΣοτ͕ݱࡏνΣο Ϋ͞Ε͍ͯΔ͔Ͳ͏͔ͳͲɺอଘঢ়ଶʹج͍ͮͯॳظ ԽΛߦ͏ͨΊʹ༻Ͱ͖·͢ɻ • ͜ΕɺonActivityCreatedͷޙɺonStartͷલʹݺͼ ग़͞Ε·͢ɻ
onCreate onViewStateRestored 30
• ϑϥάϝϯτ͕Ϣʔβʔʹදࣔ͞ΕΔͱ͖ʹݺͼग़͞ Ε·͢ɻ • ͜Ε௨ৗɺؚ·ΕΔΞΫςΟϏςΟͷϥΠϑαΠΫ ϧͷActivityͷonStartʹؔ࿈͚ΒΕ͍ͯ·͢ɻ onCreate onStart 31
• onCreateͷޙ͔ɺActivity͕ετοϓͨ͠ͱ͖onRestartͷ ޙʹݺΕ·͢ɻͦΕ͔ΒonResumeʹଓ͖·͢ɻ • ϏδϡΞϧཁૉΛඳը࢝͠ΊͨΓɺΞχϝʔγϣϯͷ։࢝࢝͠ ΊΔͷʹྑ͍ॴͰ͢ɻ • ͜ͷ͔ؔΒfinish()Λݺͼग़͢͜ͱ͕Ͱ͖·͢ɻ͜ͷ߹ɺ onStartͷޙʹϥΠϑαΠΫϧભҠʢonResumeɺonPause ͳͲʣΛ࣮ߦͤͣʹonStop͕͙͢ʹݺͼग़͞Ε·͢ɻ
• ੜΫϥεɺ͜ͷϝιουͷεʔύʔΫϥεͷ࣮Λݺͼग़ ͢ඞཁ͕͋Γ·͢ɻ ͦ͏Ͱͳ͍߹ɺྫ֎ (SuperNotCalledException)͕εϩʔ͞Ε·͢ɻ onStart 32
33 onStartͰfinishΛݺΜͩ߹ Activity Fragment ࣌ؒ
33 onStartͰfinishΛݺΜͩ߹ onStart Activity Fragment ࣌ؒ ͜͜Ͱfinish()Λίʔϧ
33 onStartͰfinishΛݺΜͩ߹ onStop onStart Activity Fragment onDestroy onDestroy onDetach ࣌ؒ
͜͜Ͱfinish()Λίʔϧ onStop onDestroyView
• ϑϥάϝϯτ͕Ϣʔβʔʹදࣔ͞ΕɺΞΫςΟϒʹ࣮ ߦ͞Ε͍ͯΔͱ͖ʹݺͼग़͞Ε·͢ɻ • ͜Ε௨ৗɺؚ·Ε͍ͯΔΞΫςΟϏςΟͷϥΠϑα ΠΫϧͷActivityͷonResumeʹؔ࿈͚ΒΕ͍ͯ· ͢ɻ onCreate onResume 34
• ΞΫςΟϏςΟ͕ϢʔβʔͱͷରΛ։࢝͢ΔͨΊʹɺ onRestoreInstanceStateɺonRestartɺ·ͨonPauseͷޙʹݺͼग़͞Ε ·͢ɻ • ͜ΕɺΞΫςΟϏςΟ͕ΞΫςΟϒʹͳΓɺೖྗΛड͚औΔ४උ͕Ͱ͖ͨ ͜ͱΛࣔ͢ΠϯδέʔλͰ͢ɻ ΞΫςΟϏςΟελοΫͷ࠷্෦ʹ͋Γɺ Ϣʔβʔʹදࣔ͞Ε·͢ɻ •
Build.VERSION_CODES.QΑΓલͷϓϥοτϑΥʔϜόʔδϣϯͰɺഉଞ తΞΫηεσόΠεΛ։͍ͨΓɺγϯάϧτϯϦιʔεʹΞΫηεͨ͠Γ͢ Δͷʹద͍ͯ͠·͢ɻ Build.VERSION_CODES.QҎ߱ɺγεςϜʹෳ ͷ࠶։͞ΕͨΞΫςΟϏςΟ͕ಉ࣌ʹଘࡏ͢ΔՄೳੑ͕͋ΔͨΊɺΘΓʹ onTopResumedActivityChangedΛ༻͢Δඞཁ͕͋Γ·͢ɻ • ੜΫϥεɺ͜ͷϝιουͷεʔύʔΫϥεͷ࣮Λݺͼग़͢ඞཁ͕͋Γ ·͢ɻ ͦ͏Ͱͳ͍߹ɺྫ֎(SuperNotCalledException)͕εϩʔ͞Ε·͢ɻ onResume 35
• ΞΫςΟϏςΟ͕γεςϜͷ࠶։͞Εͨ࠷্ҐͷҐஔΛऔಘ ·ࣦͨ͏ͱ͖ʹݺͼग़͞Ε·͢ɻ • Build.VERSION_CODES.Q͔ΒɺϚϧνΟϯυϞʔυͱϚ ϧνσΟεϓϨΠϞʔυͰෳͷΞΫςΟϏςΟΛಉ࣌ʹ࠶։ Ͱ͖·͢ɻ ͜ͷίʔϧόοΫɺΞΫςΟϏςΟ͕ΧϝϥͳͲ ͷഉଞΞΫηεσόΠεΛ։͜͏ͱ͢ΔՄೳੑ͕͋Δ͜ͱΛࣔ ͢ͷͱͯ͠ɺonResumeͷΘΓʹ༻͢Δඞཁ͕͋Γ·
͢ɻ • ΞΫςΟϏςΟ͕࠶։͞ΕͨޙɺҰ࣌ఀࢭ͞ΕΔલʹৗʹ৴ ͞Ε·͢ɻ ߹ʹΑͬͯεΩοϓ͞ΕΔՄೳੑ͕͋ΓɺΞΫ ςΟϏςΟonResume͔ΒonPauseʹҠߦͰ͖·͕͢ɺ ࠷ॳͷ࠶։ঢ়ଶΛड͚औΔ͜ͱͰ͖·ͤΜɻ onTopResumedActivityChanged 36
• ϚϧνΟϯυରԠંΓͨͨΈࣜσόΠεΛରԠ ͢Δͱ͖ʹඞͣߟྀ͕ඞཁʹͳΓͦ͏Ͱ͢ɻ • ৄͪ͘͜͠Β ʮંΓͨͨΈࣜσόΠεʹରԠͨ͠ΞϓϦͷ࡞ʯ https://developer.android.com/preview/features/ foldables onTopResumedActivityChanged 37
͜͜·ͰͰΞϓϦىಈ·Ͱͷ ίʔϧόοΫΛ֬ೝ͠·ͨ͠ɻ 38
͜Μͳײ͡ͰΞϓϦऴྃ࣌ͷίʔϧόοΫ ֬ೝ͍͖ͯ͠·͕͢ΑΖ͍͠Ͱ͔͢ʁ 39
40 ΞϓϦऴྃ࣌ͷϥΠϑαΠΫϧ
40 ΞϓϦऴྃ࣌ͷϥΠϑαΠΫϧ
41 ΞϓϦऴྃ࣌ͷϥΠϑαΠΫϧ onPause onPause onStop Activity Fragment onStop onDestroy onDestroyView
onDestroy onDetach ࣌ؒ ※super.onHogeͷޙͷλΠϛϯάͰ֬ೝ ࠶ܝ
• ϑϥάϝϯτ͕࠶։͞Εͳ͘ͳͬͨͱ͖ʹݺͼग़͞Ε ·͢ɻ • ͜Ε௨ৗɺΞΫςΟϏςΟͷϥΠϑαΠΫϧͷ ActivityͷonPauseʹؔ࿈͚ΒΕ͍ͯ·͢ɻ onCreate onPause 42
• Ϣʔβʔ͕ΞΫςΟϏςΟΛ৮Βͳ͘ͳͬͨͱ͖(ϗʔ ϜϘλϯΛԡ͢ͳͲ)ʹɺΞΫςΟϏςΟϥΠϑαΠΫ ϧͷҰ෦ͱͯ͠ݺͼग़͞Ε·͕͢ɺ͜ͷ࣌Ͱը໘ ʹදࣔ͞Εͨ··Ͱ͢ɻ onResumeͱରԠ͍ͯ͠ ·͢ɻ • ΞΫςΟϏςΟAͷલͰΞΫςΟϏςΟB͕ىಈ͞ΕΔ ͱɺ͜ͷίʔϧόοΫAͰݺͼग़͞Ε·͢ɻBɺA
ͷonPauseϝιου͕ฦͬͯ͘Δ·Ͱ࡞͞Ε·ͤ Μɻ͕ͨͬͯ͠ɺ͜͜Ͱ͍࣌ؒߦΘͳ͍Ͱͩ͘͞ ͍ɻ onPause (1/3) 43
• ͜ͷίʔϧόοΫɺΞΫςΟϏςΟͷฤूதͷӬଓతͳঢ়ଶΛอ ଘ͢ΔͨΊʹओʹ༻͞Εɺ৽͍͠ΞΫςΟϏςΟΛ։࢝͢Δͷʹ ेͳϦιʔε͕ͳ͍߹ɺ͜ͷΞΫςΟϏςΟΛڧ੍ऴྃͤͣɺԿ ࣦΘΕͳ͍Α͏ʹ͢ΔͨΊʹ༻͠·͢ɻ • ͜Ε·ͨɺ࣍ͷΞΫςΟϏςΟͷΓସ͑ΛՄೳͳݶΓ͘͢ ΔͨΊʹɺCPUΛஶ͘͠ফඅ͢ΔͷΛఀࢭ͢Δͷʹదͨ͠ॴͰ ͢ɻ •
Build.VERSION_CODES.QΑΓલͷϓϥοτϑΥʔϜόʔδϣϯͰ ɺഉଞతΞΫηεσόΠεΛดͨ͡ΓɺγϯάϧτϯϦιʔεͷ ΞΫηεΛղ์ͨ͠Γ͢Δͷʹద͍ͯ͠·͢ɻ Build.VERSION_CODES.QҎ߱ɺγεςϜʹෳͷ࠶։͞ΕͨΞΫ ςΟϏςΟ͕ಉ࣌ʹଘࡏ͢ΔՄೳੑ͕͋ΔͨΊɺΘΓʹ onTopResumedActivityChangedΛ༻͢Δඞཁ͕͋Γ·͢ɻ onPause (2/3) 44
• ΞΫςΟϏςΟ͕Ұ൪্Ͱىಈ͞Εͨ߹ɺ͜ͷݺͼग़ ͠͞Εͨޙɺ௨ৗ࣍ͷonStopΛݺͼग़͠·͢ʢ࣍ͷ ΞΫςΟϏςΟ͕࠶։͞Ε্ͯʹදࣔ͞Εͨޙʣɻͨͩ ͠ɺ߹ʹΑͬͯɺonStop͕ݺΕͣʢఀࢭঢ়ଶΛ ܦ༝ͤͣʣʹonResumeʹίʔϧόοΫ͞ΕΔ͜ ͱ͕͋Γ·͢ɻΞΫςΟϏςΟɺϚϧνΟϯυ Ϟʔυͷ߹ɺϢʔβʔʹදࣔ͞Εͨ··ͷ߹ʹɺ Ұ࣌ఀࢭঢ়ଶ(onPause)Ͱఀࢭ͢Δ͜ͱ͋Γ·͢ɻ •
ੜΫϥεɺ͜ͷϝιουͷεʔύʔΫϥεͷ࣮Λ ݺͼग़͢ඞཁ͕͋Γ·͢ɻͦ͏Ͱͳ͍߹ɺྫ֎͕ε ϩʔ͞Ε·͢ɻ onPause (3/3) 45
46 onPause͔ΒonResumeʹͳΔλΠϛϯά • ׂը໘λοϓͰonPause • ผͷΞϓϦΛબΜͩΒɺonStop ݺΕͣonResume͕ݺΕ Δ
46 onPause͔ΒonResumeʹͳΔλΠϛϯά • ׂը໘λοϓͰonPause • ผͷΞϓϦΛબΜͩΒɺonStop ݺΕͣonResume͕ݺΕ Δ
• ϑϥάϝϯτ͕͏࢝·Βͳ͍࣌ʹݺͼग़͞Ε·͢ɻ • ͜Ε௨ৗɺؚ·ΕΔΞΫςΟϏςΟͷϥΠϑαΠΫ ϧͷActivity.onStopʹؔ࿈͚ΒΕ͍ͯ·͢ɻ onCreate onStop 47
• Ϣʔβʔ͔Βݟ͑ͳ͘ͳͬͨͱ͖ʹݺͼग़͞Ε· ͢ɻ ࣍ͷϢʔβʔߦಈʹԠͯ͡ɺonRestart͔ onDestroy͕ݺΕΔ͔ɺԿίʔϧ͞Ε·ͤΜɻ • ͜ΕɺUIͷߋ৽ɺΞχϝʔγϣϯͦͷଞͷࢹ֮త ͳͷͷ࣮ߦΛఀࢭ͢Δͷʹదͨ͠ॴͰ͢ɻ • ੜΫϥεɺ͜ͷϝιουͷεʔύʔΫϥεͷ࣮
Λݺͼग़͢ඞཁ͕͋Γ·͢ɻ ͦ͏Ͱͳ͍߹ɺྫ֎ ͕εϩʔ͞Ε·͢ɻ onStop 48
49 onStopͷ͋ͱԿ͠ͳ͍λΠϛϯά • λεΫҰཡͷͱ͖
49 onStopͷ͋ͱԿ͠ͳ͍λΠϛϯά • λεΫҰཡͷͱ͖
50 onStopͷ͋ͱԿ͠ͳ͍λΠϛϯά • ϗʔϜʹͬͨͱ͖
50 onStopͷ͋ͱԿ͠ͳ͍λΠϛϯά • ϗʔϜʹͬͨͱ͖
51 onStopͷ͋ͱԿ͠ͳ͍λΠϛϯά • ઃఆ͔Βڧ੍ఀࢭͨ͠߹ • onDestoryݺΕ·ͤΜɻ
51 onStopͷ͋ͱԿ͠ͳ͍λΠϛϯά • ઃఆ͔Βڧ੍ఀࢭͨ͠߹ • onDestoryݺΕ·ͤΜɻ
52 onStopͷ͋ͱonRestartʹͳΔλΠϛϯά • όοΫάϥϯυ͔Β ͖ͬͯͨ࣌
52 onStopͷ͋ͱonRestartʹͳΔλΠϛϯά • όοΫάϥϯυ͔Β ͖ͬͯͨ࣌
• ݱࡏͷΞΫςΟϏςΟ͕Ϣʔβʔʹ࠶දࣔ͞Ε͍ͯΔ ʢϢʔβʔ͕࠶ͼͬͨʣͱ͖ʹɺonStopʢʣͷޙʹ ݺͼग़͞Ε·͢ɻ ͦͷޙʹonStart͕ଓ͖ɺonResume ͕ଓ͖·͢ɻ • ੜͷCursorΦϒδΣΫτΛ༻͍ͯ͠ΔΞΫςΟϏςΟ ͷ߹ɺ͜Ε௨ৗɺΧʔιϧΛ࠶ΫΤϦ͢ΔॴͰ ͢ʢonStopͰΧʔιϧΛඇΞΫςΟϒʹͨͨ͠Ίʣɻ
• ੜΫϥεɺ͜ͷϝιουͷεʔύʔΫϥεͷ࣮Λ ݺͼग़͢ඞཁ͕͋Γ·͢ɻ ͦ͏Ͱͳ͍߹ɺྫ֎͕ε ϩʔ͞Ε·͢ɻ onRestart 53
54 onStopͷ͋ͱonDestroyʹͳΔλΠϛϯά • ΞϓϦऴྃ࣌ • ը໘ճస࣌
54 onStopͷ͋ͱonDestroyʹͳΔλΠϛϯά • ΞϓϦऴྃ࣌ • ը໘ճస࣌
55 onStopͷ͋ͱonDestroyʹͳΔλΠϛϯά • ը໘ׂޙͷΟϯυαΠζ มߋ࣌
55 onStopͷ͋ͱonDestroyʹͳΔλΠϛϯά • ը໘ׂޙͷΟϯυαΠζ มߋ࣌
56 onStopͷ͋ͱonDestroyʹͳΔλΠϛϯά • λεΫҰཡ͔Βڧ੍ऴྃ࣌ • ͪͳΈʹɺFragmentͷ onDestoryݺΕ·ͤΜɻ
56 onStopͷ͋ͱonDestroyʹͳΔλΠϛϯά • λεΫҰཡ͔Βڧ੍ऴྃ࣌ • ͪͳΈʹɺFragmentͷ onDestoryݺΕ·ͤΜɻ
• onCreateViewʹΑͬͯ࡞͞ΕͨϏϡʔ͕ϑϥάϝ ϯτ͔ΒΓ͞Εͨͱ͖ʹݺͼग़͞Ε·͢ɻ ࣍ʹ ϑϥάϝϯτΛදࣔ͢Δඞཁ͕͋Δͱ͖ʹɺ৽͍͠ Ϗϡʔ͕࡞͞Ε·͢ɻ • ͜ΕɺonStopͷޙɺonDestroyͷલʹݺͼग़͞Ε ·͢ɻ onCreateView͕non-nullͷϏϡʔΛฦ͔ͨ͠
Ͳ͏͔ʹؔͳ͘ݺͼग़͞Ε·͢ɻ • ෦తʹɺϏϡʔͷঢ়ଶ͕อଘ͞Εͨޙɺ͔Β আ͞ΕΔલʹݺͼग़͞Ε·͢ɻ onCreate onDestroyView 57
58 onDestroyView͕ݺΕΔλΠϛϯά • ΞϓϦऴྃ࣌ • ը໘ճస࣌ • ׂը໘λοϓ࣌ • ը໘ׂޙɺΟϯυαΠζมߋ࣌
• ผͷϑϥάϝϯτʹભҠ࣌
• ϑϥάϝϯτ͕༻͞Εͳ͘ͳͬͨͱ͖ʹݺͼग़͞Ε ·͢ɻ ͜ΕɺonStopͷޙɺonDetachͷલʹݺͼ ग़͞Ε·͢ɻ onCreate onDestroy 59
60 onDestroy͕ݺΕΔλΠϛϯά • ΞϓϦऴྃ࣌ • ը໘ճస࣌ • ׂը໘λοϓ࣌ • ը໘ׂޙɺΟϯυαΠζมߋ࣌
• ↑onDestoryView͕ݺΕΔλΠϛϯάͱ΄΅ಉ͕ͩ͡ɺ ผͷϑϥάϝϯτʹભҠ࣌ʹݺΕ·ͤΜ
• ϑϥάϝϯτ͕ͦͷΞΫςΟϏςΟʹΞλον͞Εͳ ͘ͳͬͨͱ͖ʹݺͼग़͞Ε·͢ɻ ͜ΕɺonDestroy ͷޙʹݺͼग़͞Ε·͢ɻ onCreate onDetach 61
• ΞΫςΟϏςΟ͕ഁغ͞ΕΔલʹɺ࠷ऴతͳΫϦʔϯΞοϓΛ࣮ߦ͠·͢ɻ͜Εɺ ΞΫςΟϏςΟ͕ऴ͍ྃͯ͠Δʢfinish()͕ݺͼग़͞Ε͍ͯΔʣ͔ɺγεςϜ͕ΞΫ ςΟϏςΟͷ͜ͷΠϯελϯεΛҰ࣌తʹഁغͯ͠εϖʔεΛઅ͍ͯ͠ΔͨΊʹൃ ੜ͠·͢ɻ isFinishing()ϝιουΛ༻͢Δͱɺ͜ΕΒ2ͭͷγφϦΦΛ۠ผͰ͖· ͢ɻ • ɿ͜ͷϝιου͕σʔλΛอଘ͢Δॴͱͯ͠ݺͼग़͞ΕΔ͜ͱΛظ͠ͳ͍Ͱ͘ ͍ͩ͞ʂͨͱ͑ɺΞΫςΟϏςΟ͕ίϯςϯπϓϩόΠμʔͰσʔλΛฤू͍ͯ͠
Δ߹ɺͦΕΒͷฤू͜͜Ͱͳ͘onPause·ͨonSaveInstanceStateͰί ϛοτ͢Δඞཁ͕͋Γ·͢ɻ͜ͷϝιου௨ৗɺΞΫςΟϏςΟʹؔ࿈͚ΒΕͨ εϨουͳͲͷϦιʔεΛղ์͢ΔͨΊʹ࣮͞Ε·͢ɻͦͷͨΊɺΞϓϦέʔγϣ ϯͷΓͷ࣮ߦதʹഁյ͞ΕͨΞΫςΟϏςΟ͕ͦͷΑ͏ͳͷΛ͞ͳ͍Α͏ʹ͠ ·͢ɻγεςϜ͕͜ͷϝιουʢ·ͨଞͷϝιουʣΛݺͼग़ͣ͞ʹɺΞΫςΟϏ ςΟͷϗεςΟϯάϓϩηεΛڧ੍ऴྃ͢Δ߹͕͋Γ·͢ɻͦͷͨΊɺϓϩηε͕ ऴྃͨ͠ޙͦͷ··ʹ͓ͯ͘͜͠ͱΛతͱͯ͠༻͠ͳ͍Ͱ͍ͩ͘͞ɻ • ੜΫϥεɺ͜ͷϝιουͷεʔύʔΫϥεͷ࣮Λݺͼग़͢ඞཁ͕͋Γ·͢ɻͦ ͏Ͱͳ͍߹ɺྫ֎͕εϩʔ͞Ε·͢ɻ onDestroy 62
ײ 63
64 ײ • Android 10ͰંΓͨͨΈࣜσόΠεʹؔ࿈ͨ͠ίʔϧ όοΫonTopResumedActivityChanged͕૿͑ͯͨΓ͠· ͨ͠ͷͰɺࠓޙ͜ͷΑ͏ͳσόΠεΛରԠ͢Δ߹ཁ νΣοΫͰ͢ɻ • Fragmentͷ৽͍͠ίϯετϥΫλ͕૿͑ͯͨΓͯ͠ɺ
৽͍͠ൃݟ͋Γ·ͨ͠ɻ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ 65