Answers for "global variable in kotlin android"

1

global variable in kotlin android

creat a class file like
GlobalClass.kt
###
import android.app.Application

class GlobalClass:Application() {
    var your_variable = "the variable"
}
###
then add it to AnroidManifest.xml
<application
	android:name=".GlobalClass"
###
now in your pref activity
var gv_root = GlobalClass()
var gv_extract = gv_root.your_variable
###
PrintL.(gv_extract)
OutPut = the variable
Posted by: Guest on October-28-2021
0

kotlin global variable

In Kotlin, A global variable is a variable that is declared at the top of the program and outside all functions similar to C and C++. A local variable can only be used in the particular block where it is declared. A global variable can be used in all functions.
Posted by: Guest on February-27-2021
0

kotlin global variable

var x = 100

fun fn() { 
    x = x + 100 
}

fun main(args: Array<String>) {
    println("X Value : $x")
    
    fn()
    
    println("X Value : $x")
}
Posted by: Guest on February-27-2021

Browse Popular Code Answers by Language