Do Scala objects survive reboot activity on Android?

I am writing an Android application in Scala and I could not find a clear answer to this question.

My application contains an object with a bunch of static data defined in vals. Data includes class instances.

My question is: what happens to my object when Android decides to kill this activity and then restarts it? I understand that objects in Scala can be used to achieve a similar goal for static values ​​in Java, but are not actually implemented that way in the generated bytecode. Does Android know to reinitialize my object when it restarts activity? Are there circumstances under which this will not be done, or where should I be careful?

If the answer to this is “all right”, I understand that an object consisting of mutable data will be completely different. In this case, I am sure that I will need to explicitly save / restore such objects in order to save the state. But it seems silly that you need to save / restore data that is always the same and is tightly connected with the APK itself.

+5
source share
1 answer

In short, objects are translated into single objects, and one instance is stored in a static destination field. Therefore, the objects will be reinitialized, and you will need serialization to restore the same data for mutable objects.

Scala ( Odersky .), 31, , - .

, :

object App {
 def main(args: Array[String]) {
  println("Hello, world!")
 }
}

App$, singleton. , singleton , public static final App$ MODULE$ = new App$();, . javap App$ - , jad . , Scala App, Java. , App.main scala App, , , java App .

+3

All Articles