How to convert PersistableBundle to Bundle in android?

568 Views Asked by At

I am looking for a way to convert PersistableBundle to Bundle in android. Is there any simpler way to do this? They both do not inherit from same class and hence i cannot typecast them.

Edit:

I found this way to copy

public static Bundle getBundleFromPersistableBundle(final PersistableBundle persistableBundle) {
    Bundle bundle = new Bundle();
    if(persistableBundle == null) {
        return null;
    }
    bundle.putAll(persistableBundle);
    return bundle;
}
1

There are 1 best solutions below

5
On BEST ANSWER

You can construct a Bundle from a PersistableBundle instance.

PersistableBundle pb = new PersistableBundle();
Bundle b = new Bundle(pb);

See the documentation for this constructor:

Constructs a Bundle containing a copy of the mappings from the given PersistableBundle. Does only a shallow copy of the PersistableBundle -- see deepCopy() if you don't want that.