December 2017
Intermediate to advanced
260 pages
7h 34m
English
Constants objects or variables are something where the value never changes throughout the life of an application. Do not make a mistake considering any val as constants. val are not constants, but they are immutable objects where a value once assigned cannot be changed, more like final objects in Java.
Companion objects do define constants that can be accessed in a static way. But the best way to define constants in Android is using a top-level file and dumping all your constants there.
To come to the conclusion of the previous line we did various experiments.
We started by using a simple companion object:
class Constants { companion object { val TWITTER_SUCCESS = 140 } }
Decompiling the preceding code results in the ...
Read now
Unlock full access