DailogFragment - getArguments / setArguments - why pass arguments in a bundle?

In the official example, the http://developer.android.com/reference/android/app/DialogFragment.html#BasicDialog fragment is created using the static factory method, which wraps the arguments in the Bundle and calls the no-args constructor, passing args with setArguments (bundle ) - so my question is: why not just make a public constructor with these arguments? What is the reason for using the getArguments / setArguments fragment methods - is it possible Dialog is not guaranteed to be recreated every time, but is reused? if so, when does this happen? Thanks in advance.

+5
source share
1 answer

Forced use of no-arguments arguments, the default constructor template allows the system to dynamically recreate a fragment if necessary. From the docs:

All subclasses of Fragment must include a public empty constructor. A structure often re-creates an instance of a fragment class when necessary, in particular during state recovery, and should be able to find this constructor to create it. If an empty constructor is not available, in some cases the runtime will be thrown during state recovery.

“often” and “in some cases” leaves it uncertain. But not satisfying your curiosity ... the arguments are this!

+7
source

All Articles