Day 6/100: Context in Android — The Wrong One Will Leak Your Entire Activity
This is Day 6 of my 100 Days to Senior Android Engineer series. Each post: what I thought I knew → what I actually learned → interview implications. 🔍 The concept Context is one of those Android c...

Source: DEV Community
This is Day 6 of my 100 Days to Senior Android Engineer series. Each post: what I thought I knew → what I actually learned → interview implications. 🔍 The concept Context is one of those Android classes you use dozens of times per day without thinking about it. You pass it to constructors, use it to inflate views, start activities, access resources. But Context isn't one thing — it's a family of related objects with very different lifetimes. Pass the wrong one into a long-lived object, and you've just anchored that object to a screen that the user may have left minutes ago. The screen can't be garbage collected. You've created a memory leak. Not a theoretical one. A real one that affects every user who navigates back to that screen. 💡 What I thought I knew My rule of thumb used to be: "Use applicationContext when in doubt." That's not wrong exactly — applicationContext won't leak. But it's incomplete, and applying it blindly causes a different class of bugs: UI operations that crash,