Issue
I'm new to Kotlin. And I need a help that I can't understand to java and kotlin.
For Java I made it. But for kotlin I can't The thing is, I create a Global kotlin class public class Global : Application()
In MainFest I declared that android:name=".Global"
and in Global Class I declared a variable:
public class Global : Application() {
open var homeAPIResponse: String = "defaultValue"
}
When I set to this global variable any value, it's won't save and when I fetch the value always it's showing default value. I can't understand the java type getter and setter methods in kotlin. Please help me.
I tried that:
global = Global()
global.homeAPIResponse = "2nd Text"
Log.d("testingTag", "Testing modified response >>>> " + global.homeAPIResponse)
In log it's always showing the defaultvalue.
========================================================================= Guys, my purpose is to save some value globally that, after moves one activity to another, the value will not erase.
Please help me with proper described example cause I searched a lot on stack overflow. and coudn't get it.
Thanks in Advance
Solution
Maybe try like this:
public class Global : Application() {
companion object {
@JvmField
var homeAPIResponse: String = "defaultValue"
}
}
In other activity:
Global.homeAPIResponse = "new value"
Answered By - alexrnov