简体   繁体   中英

Get value from java application class in kotlin service

i have a java application class and i want to get a value from it in kotlin service.

i try to do it with this code but it's return null

myValue = (application as App).getNumValue

some of my code

Application Class:

private String numValue = "";


public String getNumValue() {
    return numValue;
}

public void setNumValue(String numValue) {
    this.numValue = numValue;
}

java Activity for set value:

 ((App) this.getApplication()).setNumValue(enNum);

Kotlin Service And Read Value:

myValue = (application as App).getNumValue()

Toast.makeText(this, myValue +"", Toast.LENGTH_SHORT).show()

I was solved my problem with:

val myValue = (this.application as App).getNumValue()

Toast.makeText(this, myValue +"", Toast.LENGTH_SHORT).show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM