安卓(Android) 怎么将包含char[]的两个parcelable bundle连接起来形成一个parcelable

2019年10月13日14:24:54安卓(Android) 怎么将包含char[]的两个parcelable bundle连接起来形成一个parcelable已关闭评论 211 1216字阅读4分3秒

1.简介

安卓(Android) 怎么将包含char[]的两个parcelable bundle连接起来形成一个parcelable?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import android.os.Bundle;

import android.os.Parcelable;

public class Main {
    
    public static final String BUNDLE_PROPERTIES = "properties";

    
    public static Parcelable assembleParcelProps(Parcelable one,
            Parcelable another) {
        Bundle bundle = new Bundle();
        char[] characters = null;
        char[] characters1 = null;
        char[] characters2 = null;
        int length = 0;

        if (one != null) {
            characters1 = ((Bundle) one).getCharArray(BUNDLE_PROPERTIES);
            if (characters1 != null)
                length += characters1.length;
        }
        if (another != null) {
            characters2 = ((Bundle) another)
                    .getCharArray(BUNDLE_PROPERTIES);
            if (characters2 != null)
                length += characters2.length;
        }

        characters = new char[length];

        if (characters1 != null && characters2 != null) {
            System.arraycopy(characters1, 0, characters, 0,
                    characters1.length);
            System.arraycopy(characters2, 0, characters,
                    characters1.length, characters2.length);
        } else if (characters1 != null && characters2 == null) {
            System.arraycopy(characters1, 0, characters, 0,
                    characters1.length);
        } else if (characters1 == null && characters2 != null) {
            System.arraycopy(characters2, 0, characters, 0,
                    characters2.length);
        }

        bundle.putCharArray(BUNDLE_PROPERTIES, characters);
        bundle.setClassLoader(Bundle.class.getClassLoader());
        return bundle;
    }
}

 
继续阅读