0 votes
in JQuery by
What is use only the default constructor to create a Fragment in Android?

1 Answer

0 votes
by
In short, Fragments need to have a no-args constructor for the Android system to instantiate them. Your Fragment subclasses need a public empty constructor as this is what's being called by the framework.

It is used in the case when device has to restore the state of a fragment. No data will be passed and a default fragment will be created and then the state will be restored. Since the system has no way to know what you passed in your constructor or your newInstance, default constructor will be used and saved bundle should be passed via onCreate after the fragment is actually instantiated with the default constructor.

Related questions

0 votes
asked Jun 22, 2020 in JQuery by DavidAnderson
0 votes
asked Sep 21, 2020 in JQuery by JackTerrance
...