Hello folks. Let's say i have a method to check internet connection inside my ViewModel that's something along these lines:
internal fun callToCheckIfInternetConnectionIsAvailable(
onConnectionAvailable: () -> Unit = {},
onConnectionUnavailable: () -> Unit = {}
) {
if(networkChecking.checkIfInternetConnectionIsAvailable()) {
onConnectionAvailable()
} else {
onConnectionUnavailable()
}
}
And then i pass something like this from my Activity:
viewModel.callToCheckIfInternetConnectionIsAvailable({
onConnectionUnavailable = { Toast.makeText(applicationContext, "Bla", Toast.LONG).show() }
})
When it is passed to my ViewModel, it will be interpreted as a method since it's wrapped by a lambda. Although that is true, the content inside that lambda, contains lifecycle-related references such as a View. Could passing this instruction to a ViewModel cause a memory leak if the LifecycleOwner(Activity/Fragment) gets destroyed in the meantime? And besides that, would it break the MVVM pattern? Really curious to know your thoughts on the matter. Thank you in advance K