Home > Blockchain >  What would happen to Activity's properties when the onDestroy call?
What would happen to Activity's properties when the onDestroy call?

Time:07-21

Two types of scenarios might happen when the onDestroy method calls! One is when config change occurs and another one is when the activity is finishing. Assuming we have an Activity with some properties. What would happen to these properties in these two scenarios?(I mean are they going to be dismantled or going to be persisted)

CodePudding user response:

Activities are instances managed by the android framework! When configuration changes occur, they are destroyed and recreated. So their properties are too. To make these properties persist you have to add another mechanism (like saving in a bundle or using a ViewModel). When the activity is finishing, their references are release. In both cases the android framework stops referencing the activity and both the activity and its properties become available to be garbage collected, unless you hold to them a reference somewhere or you hold a reference to the activity itself (which is never recommended!).

  • Related