I’m wondering how to properly obtain a LayoutInflater instance and how long to keep it around.
The android doc states:
It is never used directly. Instead, use getLayoutInflater() or
getSystemService(String) to retrieve a standard LayoutInflater
instance that is already hooked up to the current context and
correctly configured for the device you are running on.
My questions:
- Is getSystemService(String) fast so I can call it everywhere i need an instance?
- Should i store the inflater-instance in a variable for later use?
- I think I saw some interfaces in the SDK, that pass
LayoutInflater, why do they do that?
AFAIK, yes, though you may want to run a test and examine the method trace in Traceview to confirm.
If you are in a tight loop, hang onto the instance in a local variable versus creating calling
getLayoutInflater()each time. Otherwise, I am not aware that it is a worthwhile optimization.To save you the trouble of calling
getLayoutInflater().