How can I convert a Bundle to a PersistableBundle?

Viewed 3477

API21 released the PersistableBundle which is a bundle that the system retains for various purposes (JobScheduler jobs, ShortcutInfos etc). I'd like an easy way to convert the Bundle's that are present in my old code to PersistableBundle's...how can I do it?

3 Answers

Converting form Bundle to PersistableBundle

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

Converting from PersistableBundle to Bundle

PersistableBundle pb = new PersistableBundle();
Bundle b= new Bundle();
b.putAll(pb);
Related