I recently came across an interesting question on StackOverflow regarding Fragment instantiation:
What is the difference between
MyFragment.newInstance()? Should I prefer one over the other?
Good question. The answer, as the title of this blog suggests, is a matter of proper design. In this
newInstance() method is a “static factory method,” allowing us to initialize and setup a
Fragment without having to call its constructor and additional setter methods. Providing static
factory methods for your fragments is good practice because it encapsulates and abstracts the steps
required to setup the object from the client. For example, consider the following code: