В примере базовый каркас приложения по работе с GPS.
Вопрос по инициализации переменной locListenerInterface в классе GpsClass. Как понять концептуально, что мы присваиваем этой переменной при определении?
private var locListenerInterface: LocListenerInterface = (myContext as LocListenerInterface)
Работает так же
private var locListenerInterface: LocListenerInterface = (myContext as MainActivity)
Как вообще правильно инициализировать эту переменную, для передачи координат в MainActivity с класса GpsClass через интерфейс LocListenerInterface
class MainActivity : AppCompatActivity(), LocListenerInterface {
private val gps = GpsClass(this)
override fun onLocationChangedInterface(location: Location) {
// show updated location
}
}
interface LocListenerInterface {
fun onLocationChangedInterface (location: Location)
}
class GpsClass (private val myContext: Context) {
private var locListenerInterface: LocListenerInterface = (myContext as LocListenerInterface)
fun onLocationChanged(location: Location) {
locListenerInterface.onLocationChangedInterface(location)
}
}