Reputation: 2060
If I am creating a Fragment class, I've seen written everywhere that it is a good idea to include an empty constructor (although I'm not sure why, because I always assumed Java had an empty constructor invoked under the hood for any Java class as long as you don't create a constructor with arguments, and Android doesn't like you making Fragments with constructors with arguments anyway).
But if I am making a newInstance() method (so I can set up my Bundle with default arguments), do I have to create the empty constructor?
If it is enough to include newInstance() and not an empty constructor, could I do this for all my fragments even if there are no arguments in the bundle? Is there any downside to this?
Upvotes: 0
Views: 189
Reputation: 1085
When making a static getInstance()
method you'll be using that method to get a new instance of that Fragment
. You wont be needing an empty constructor.
Upvotes: 2