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
310
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
710
Flutter製チャットアプリを支える技術 / Technologies that support a Flutter chat application
yasi
1
790
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
630
Retrofit2の仕組み 〜オリジナルConverterを作ってみる〜 / How Retrofit2 works ~ Try making your own Converter ~
yasi
0
520
アプリ内課金 プラグインの現状 / Present situation of in-app purchase in Flutter
yasi
5
2.3k
AndroidやiOSのアプリ開発でいつも私がやっていることをFlutterでやってみた / Flutter development as usual
yasi
3
1.8k
Intro to Flutter
yasi
0
770
Other Decks in Programming
See All in Programming
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
130
talk-with-local-llm-with-web-streams-api
kbaba1001
0
180
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
450
MCP with Cloudflare Workers
yusukebe
2
220
今からはじめるAndroidアプリ開発 2024 / DevFest 2024
star_zero
0
1k
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
선언형 UI에서의 상태관리
l2hyunwoo
0
140
Refactor your code - refactor yourself
xosofox
1
260
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
Typedesign – Prime Four
hannesfritz
40
2.4k
Faster Mobile Websites
deanohume
305
30k
4 Signs Your Business is Dying
shpigford
181
21k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Designing for Performance
lara
604
68k
A designer walks into a library…
pauljervisheath
204
24k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Thoughts on Productivity
jonyablonski
67
4.4k
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