We know that Application class behaves as a singleton so we can store there some app session data, and interact to it from different screens. For example we do this in Java like so:
public class App extends Application {
public static String myString;
@Override
public void onCreate() {
super.onCreate();
}
public static String getMyString() {
return myString;
}
public static void setMyString(String myString) {
App.myString = myString;
}
}
And we ca use it like so App.setMyString("blah blah")
and access this value from everywhere like so: App.getMyString()
I tried to change this to kotlin with no success:
class App : Application() {
override fun onCreate() {
super.onCreate()
}
companion object {
var myString: String = null
fun setMyString(str: String) {
myString = str
}
fun getMyString(): String? {
return myString
}
}
init {
myString = String()
}
}
That variable doesn't keep my value