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
350
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
750
Other Decks in Programming
See All in Programming
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
140
プロジェクト新規参入者のリードタイム短縮の観点から見る、品質の高いコードとアーキテクチャを保つメリット
d_endo
1
1k
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
390
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
170
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
3
400
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
210
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.7k
Importmapを使ったJavaScriptの 読み込みとブラウザアドオンの影響
swamp09
4
1.2k
CSC305 Lecture 13
javiergs
PRO
0
130
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
260
デプロイを任されたので、教わった通りにデプロイしたら障害になった件 ~俺のやらかしを越えてゆけ~
techouse
52
32k
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
19
1.1k
Writing Fast Ruby
sferik
626
61k
KATA
mclloyd
29
13k
GitHub's CSS Performance
jonrohan
1030
460k
Navigating Team Friction
lara
183
14k
The Language of Interfaces
destraynor
154
24k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
Embracing the Ebb and Flow
colly
84
4.4k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
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