GPack
GPack

Reputation: 2504

Static Fragment retains Activity's static variables?

I have a static Fragment with setRetainInstance(true) inside an Activity, and this Fragment uses an Activity's member static variable. I see that after an orientation change the value of that static variable is retained without need to saving it on Activity's onSaveInstanceState(). Can someone explain to me why? Thanks

Upvotes: 0

Views: 903

Answers (2)

vinitius
vinitius

Reputation: 3274

Static members belong to the class itself and not to the instances of that class. Check here for a simple example:

https://www.caveofprogramming.com/java/java-for-beginners-static-variables-what-are-they.html

Upvotes: 0

Eric S.
Eric S.

Reputation: 1502

Static members aren't tied to the Activity lifecycle.

Upvotes: 2

Related Questions