To add onto Tenfour04's answer, another way you could write your get() version is:
val myVariable: String get() {
return activity.myName
}
And that's clearly a function, right? You call it, it returns a String. When a function is simple and returns a value, you can format it as a single-expression function which looks like this:
// block function
fun something(): String {
return coolString
}
// single-expression function - you can omit the type too, if you like
fun something(): String = coolString
So the single-expression equivalent for your getter is
val myVariable: String get() = return activity.myName
The fact it's a val changes things - there are special getter and setter functions you can add to vals and vars, and you're sort of "tacking on" the function at the end of the variable declaration. Because it's a val, it's a property - you read it like a value, like println(myVariable). It's not a function, so you don't call it like println(myVariable()) or anything.
But in this case, because it has this getter function, under the hood Kotlin is calling that function whenever you read the value. And really, anything can happen in there! The value could be completely different every time. Maybe there's no value stored at all, and the getter just calls some other function to generate a value. But the code reading myVariable doesn't know or care about that - it just accesses the variable, and sees a value.
They're basically equivalent to the Java-style getter and setter functions:
fun getMyVariable(): String {
// or whatever you want to return
return activity.myName
}
fun setMyVariable(value: String) {
// do whatever with the value - store it in a variable, record it in some database, etc
}
Except you don't need to treat them as special and call a function to access them - they look and act just like a plain old variable! (And in fact, if you're calling Java setters and getters named like this, Kotlin will let you access them like properties)
So yeah, both the versions in the original question can be accessed the same way - that's the idea! But one is a basic variable - a val in fact, so it's a fixed value. The other is a getter which can do anything, including returning different values over time, calculating stuff on demand, or even just pointing at other values - maybe you want to give access to the other variable, especially if it's a var, or maybe in some versions of a class property A is identical to property B so it's easier to keep one updated and let the other just say "whatever that one says"