Example usage for android.os PersistableBundle putPersistableBundle

List of usage examples for android.os PersistableBundle putPersistableBundle

Introduction

In this page you can find the example usage for android.os PersistableBundle putPersistableBundle.

Prototype

public void putPersistableBundle(@Nullable String key, @Nullable PersistableBundle value) 

Source Link

Document

Inserts a PersistableBundle value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:Main.java

@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   w w  w. j  a  v a  2  s.  c  o m*/
    }
    return persistableBundle;
}