Reputation: 21
If I set arguments of a fragment myfragment to a Bundle mybundle, am I guaranteed that if I change the contents of mybundle later down the road, myfragment's call to getArguments() will be consistent with the contents of mybundle?
i.e.
mybundle.putString("background", "red");
myfragment.setArguments(mybundle);
... later ...
mybundle.putString("background", "orange");
myfragment.createLayoutFromBundle(myfragment.getArguments());
Upvotes: 0
Views: 173
Reputation: 1007296
The arguments Bundle
is part of the fragment's saved instance state. If the fragment is destroyed and re-created, your newly-created fragment will have an arguments Bundle
with the same contents as did the original Bundle
. However, the Bundle
object may be different.
This will most easily seen when:
Bundle
You will have the same data in the Bundle
as before, but the Bundle
object will be newly-created.
Upvotes: 0
Reputation: 55360
Yes. Check the source code for the Fragment
class. The bundle is not copied or anything, just returned as-is.
public void setArguments(Bundle args) {
if (mIndex >= 0) {
throw new IllegalStateException("Fragment already active");
}
mArguments = args;
}
/**
* Return the arguments supplied when the fragment was instantiated,
* if any.
*/
final public Bundle getArguments() {
return mArguments;
}
Upvotes: 1