PersistableBundle.java 文件源码

java
阅读 37 收藏 0 点赞 0 评论 0

项目:JobSchedulerCompat 作者:
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@RestrictTo(RestrictTo.Scope.LIBRARY)
public PersistableBundle(android.os.PersistableBundle bundle) {
    map = new HashMap<>(bundle.size());
    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);
        if (value == null || value instanceof String || value instanceof Integer || value instanceof Long
                || value instanceof Double || value instanceof Boolean || value instanceof String[]
                || value instanceof int[] || value instanceof long[] || value instanceof double[]
                || value instanceof boolean[]) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 && key.startsWith(PREFIX_BOOLEAN_COMPAT)) {
                key = key.substring(PREFIX_BOOLEAN_COMPAT.length());
                if (value instanceof Integer) {
                    Integer intValue = (Integer) value;
                    value = intValue != 0;
                } else if (value instanceof int[]) {
                    int[] intArrayValue = (int[]) value;
                    boolean[] boolArrayValue = new boolean[intArrayValue.length];
                    for (int i = 0; i < boolArrayValue.length; i++) {
                        boolArrayValue[i] = intArrayValue[i] != 0;
                    }
                    value = boolArrayValue;
                }
            }
            map.put(key, value);
        } else if (value instanceof android.os.PersistableBundle) {
            map.put(key, new PersistableBundle((android.os.PersistableBundle) value));
        } else {
            throw new IllegalArgumentException("Unsupported value type key=" + key + " value=" + value);
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号