I have this following function.
private val onConnect = Emitter.Listener {
if(fromReconnect) {
return
}
Log.d("Socket", "Socket Connected")
val hndlr = Handler(Looper.getMainLooper())
hndlr.post{ Toast.makeText(applicationContext, "Socket Connected", Toast.LENGTH_SHORT).show() }
if (isTryLogin){
reLogin()
}
}
I am trying to return from the function if fromReconnect flag is set. But Android Studio is throwing return not allowed here error. But when I change return to return@Listener it's working fine.The IDE hints it's an anonymous function. Why do we need to return@Listener this instead of just return?