Android examples for android.os:Bundle
Convert Bundle To Persistable Bundle
import java.util.Set; import android.annotation.TargetApi; import android.os.Build; import android.os.Bundle; import android.os.PersistableBundle; public class Main { @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) public static PersistableBundle bundleToPersistableBundle(Bundle bundle) { Set<String> keySet = bundle.keySet(); PersistableBundle persistableBundle = new PersistableBundle(); for (String key : keySet) { Object value = bundle.get(key); if (value instanceof Boolean) { persistableBundle.putBoolean(key, (boolean) value); } else if (value instanceof Integer) { persistableBundle.putInt(key, (int) value); } else if (value instanceof String) { persistableBundle.putString(key, (String) value); } else if (value instanceof String[]) { persistableBundle.putStringArray(key, (String[]) value); } else if (value instanceof Bundle) { PersistableBundle innerBundle = bundleToPersistableBundle((Bundle) value); persistableBundle.putPersistableBundle(key, innerBundle); }//from www . j av a 2 s .c om } return persistableBundle; } }