1

I came across the following methods:

Environment.getDataDirectory() : /data

and

getFilesDir() : /data/data/package/files

One method uses Environment and other does not.

whats the significance. It would be simple to use without Environment because the method names are not same.

Santhosh
  • 9,965
  • 20
  • 103
  • 243
  • Try to read this: [link](http://stackoverflow.com/questions/21230629/getfilesdir-vs-environment-getdatadirectory). – Rucsi May 30 '16 at 08:14
  • In that post, there is no mention of why its used like that. Instead it says what each one means, which i also understand. – Santhosh May 30 '16 at 08:44

1 Answers1

1

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...

Rucsi
  • 284
  • 1
  • 10
  • You also can search and read about static versus non-static methods in Java, there is plenty of info available – Rucsi May 30 '16 at 11:11