Just wondering on why the implementors decided for the developers to pass the context (even though the system services seem more like a singleton for the developers, and we mostly don't even care):
LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(layout);
I am asking this more because of an implicit fear of leaking memory/context whenever I play with context. Is there a possibility of mis-handling context here ?
In Android, your app's Context is essentially like a pipe connecting it to the system services. A lot of the system services are singletons, but you cannot arbitrarily access them. The Context class acts as a middleman to receive and pass the service you need to you.
LayoutInflater.from(context);
simply goes and calls context.getSystemService()
using the supplied context, which is your application's.
In essence, you app and Android are two separate things running simultaneously and Context adds as a pipe to connect them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With