Passing objects in to Fragments

后端 未结 2 666
醉酒成梦
醉酒成梦 2020-12-05 02:10

I\'ve been working with lots of Fragments recently and have been using two distinct methods of passing in objects to the Fragments, but the only difference that

2条回答
  •  失恋的感觉
    2020-12-05 02:52

    There are 3 ways to pass objects to a fragment

    They are:

    1. Passing the object through a setter is the fastest way, but state will not be restored automatically.
    2. setArguments with Serializable objects is the slowest way (but okay for small objects, I think) and you have automatic state restoration.
    3. Passing as Parcelable is a fast way (prefer it over 2nd one if you have collection of elements to pass), and you have automatic state restoration.

    http://developer.android.com/reference/android/os/Parcelable.html

提交回复
热议问题