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

Elyes

03/10/2020, 3:17 PM
Does anyone know why the
onDestory
function of a fragment wouldn’t be called when closing the app ?
s

Sean Keane

03/10/2020, 3:19 PM
is it called when you kill the app from the background?
e

Elyes

03/10/2020, 3:21 PM
no
s

Sean Keane

03/10/2020, 3:21 PM
Is on pause?
e

Elyes

03/10/2020, 3:22 PM
it is
But it’s also called when the app just goes to background. So it’s not indicative of whether the fragment was destroyed or not
e

Elyes

03/10/2020, 3:30 PM
I’m having a problem with the Fragment’s onDestroy not the Activity’s
s

Sean Keane

03/10/2020, 3:32 PM
As far as I know,
onDestroy()
is not guaranteed to be called unless you explicitly call
onFinish()
.
s

satyan

03/10/2020, 3:33 PM
Also, if you use
setRetainInstance(true)
,
onDestroy
won’t be called 🙂
And fragment’s
onDestroy
is linked to its Activity’s
onDestroy
so the link from @Kris Wong is relevant:
There are situations where the system will simply kill the activity’s hosting process without calling this method (or any others) in it, so it should not be used to do things that are intended to remain around after the process goes away.
👍 1
e

Elyes

03/10/2020, 3:37 PM
Alright, thanks for the insight guys
🤖 1
8 Views