Member variables vs setArguments in Fragments

前端 未结 4 813
攒了一身酷
攒了一身酷 2020-12-12 13:02

I\'ve noticed that in the Android reference for Fragments (notably DialogFragment) that they do a couple of things different from what I\'d expect:

1). Use pub

4条回答
  •  攒了一身酷
    2020-12-12 13:28

    I am pretty new to Android programming but this is my current understanding of the issue:

    The constructor for Fragments cannot have any parameters. When your activity is paused your Fragment can be released. Before your activity is resumed, the system creates a new version of your Fragment calling the constructor. If a non-default constructor is used, how is Android supposed to know what the types and values are for the arguments to your Fragments constructor?

    I don't believe that bundle is released. The bundle is kept around precisely so that it can be passed back to your Fragment after it has been recreated with the default constructor.

    Philipp Reichart eluded to this in his post (actually more than eluded.)

提交回复
热议问题