https://kotlinlang.org logo
#android
Title
# android
a

AzMoo

10/02/2018, 12:19 AM
I’ve noticed that FragmentActivity.activity can be null, in what situation could this occur? Can the activity be destroyed without the destruction of the fragment?
a

Allan Wang

10/02/2018, 1:12 AM
I don't think so, but a fragment can be detached from an Activity. See https://stackoverflow.com/questions/6215239/getactivity-returns-null-in-fragment-function
g

gildor

10/02/2018, 2:00 AM
Can the activity be destroyed without the destruction of the fragment
Sure! Fragment detached, Activity is destroyed. It’s completely valid case
s

Sam

10/02/2018, 12:49 PM
FYI, requireActivity will throw an exception but otherwise always a non null return type
5 Views