My co-worker told me the following: “You said there can be a memory leak here. I looked for a solution and saw that we can use a WeakReference<Context> to wrap the Activity context, that way it won’t leak.”
To which I said, “that’s great, except that’s a hack, and it doesn’t solve the real problem, so don’t.”
And then he said: “But I don’t understand what you mean. Show me an article that explains the real problem you talk about and why I shouldn’t use a WeakReference”.
Once I explained the real problem, he said “this is a different problem, but now I know why we shouldn’t use WeakReference”.
Many years ago in school I was learning about matrices. I don’t remember much of it, but what I do remember was thinking, “but… what do you actually do with that knowledge?”
I’ve been playing around with ViewModel, LiveData and lastly Coroutines, now that the latest are stable in Kotlin 1.3. I believe and hope I came up with a setup that allows clean, (somehow) isolated and concise code. Some might want to split things up even more (and nothing in here forbids it).
Google has rebranded their support libraries to be named Jetpack (aka AndroidX). Developers will need to make changes to account for this. This article will explain what this means, and how to get started converting your project to use the new components.