0

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)

  • 1
    All its non persistent properties in memory (RAM) will be destroyed unless you save and reload them using saved instance bundle. However the saved state bundle is only for the configuration changes. If you want to save aome properties permanently you must either use local files like shared preferences or any you create, or implement database if data is relatively complex. – Kozmotronik Jul 21 '22 at 08:58

1 Answers1

1

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!).

Brian Alex
  • 125
  • 1
  • 10