Since the Android system uses the default no-arg constructor when recreating a fragment, we should not pass values over an overloaded constructor with arguments when we instantiate it.
The correct way to instantiate a new fragment and passing values to it, is by creating a bundle, setting arguments on this bundle using setArguments() method and then passing it to our fragment. Inside the fragment we then retrieve this bundle and get the values out of it. A clean way to do this is by creating a “factory method”.
I hope you learned something! Thank you for reading.
You can find me on Twitter and Linkedin!
Click the 👏 to show your support and share it with other fellow Medium users.