Well, either I don't understand what you don't understand, either you don't understand the difference between a call of a method like Environment.method()
and method()
...
If that's what you want to understand, why the class name is written at the first call, is because the first method is a STATIC one and you don't need an instance of that class to call it. It also belongs to Environment class. ALL static methods are called with the name of their class(when you are inside the class, ex. Test class or a subclass, then and only then you can call without the name of the class in front of its call. And even so, you can put the class name there...
The getFilesDir()
is a method that needs an instantance of the class where it belongs - that is ContextWrapper - or an instance of a subclass of it to be called on... So, if you are in an Activity (which is an indirect subclass of ContextWrapper), you can call it like : this.getFilesDir()
or simply getFilesDir()
. You can also call it like getActivity().getFilesDir()
from a Fragment or getApplication().getFilesDir()
and so on... You can go to ContextWrapper Class from Android and look to the hierarchy.
Sorry if this explanation was not what you needed, but I understand you know what these methods are used for...