0
我正在尋找一種方法來將PersistableBundle轉換爲android中的Bundle。有沒有更簡單的方法來做到這一點?他們都不是從同一個班級繼承而來的,因此我無法對他們進行類型轉換。如何將PersistableBundle轉換爲android中的Bundle?
編輯:
我發現這種方式來複制
public static Bundle getBundleFromPersistableBundle(final PersistableBundle persistableBundle) {
Bundle bundle = new Bundle();
if(persistableBundle == null) {
return null;
}
bundle.putAll(persistableBundle);
return bundle;
}
我發現了一個辦法做到這一點: 公共靜態捆綁getBundleFromPersistableBundle(最終PersistableBundle persistableBundle){ 捆綁包=新包(); if(persistableBundle == null){ return null; } bundle.putAll(persistableBundle); return bundle; } – user2267399
如果使用'null' PersistableBundle參數調用此代碼片段,則會不必要地創建&放棄Bundle。檢查null參數* first,*,並且只在實際要返回的時候分配Bundle。 – ctate
@ctate這段代碼片段也定義了PeristableBundle,所以它根據定義不爲空 –