如何将 PersistableBundle 转换为 android 中的 Bundle?
How to convert PersistableBundle to Bundle in android?
我正在寻找一种将 PersistableBundle 转换为 android 中的 Bundle 的方法。有没有更简单的方法来做到这一点?它们都不是从同一个 class 继承的,因此我无法对它们进行类型转换。
编辑:
我找到了这种复制方式
public static Bundle getBundleFromPersistableBundle(final PersistableBundle persistableBundle) {
Bundle bundle = new Bundle();
if(persistableBundle == null) {
return null;
}
bundle.putAll(persistableBundle);
return bundle;
}
您可以从 PersistableBundle 实例构建 Bundle。
PersistableBundle pb = new PersistableBundle();
Bundle b = new Bundle(pb);
有关此构造函数,请参阅 the documentation:
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.
我正在寻找一种将 PersistableBundle 转换为 android 中的 Bundle 的方法。有没有更简单的方法来做到这一点?它们都不是从同一个 class 继承的,因此我无法对它们进行类型转换。
编辑:
我找到了这种复制方式
public static Bundle getBundleFromPersistableBundle(final PersistableBundle persistableBundle) {
Bundle bundle = new Bundle();
if(persistableBundle == null) {
return null;
}
bundle.putAll(persistableBundle);
return bundle;
}
您可以从 PersistableBundle 实例构建 Bundle。
PersistableBundle pb = new PersistableBundle();
Bundle b = new Bundle(pb);
有关此构造函数,请参阅 the documentation:
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.