2

我正在尝试将自定义传递到我在主屏幕上安装的快捷方式中,但是一旦创建快捷方式Object,我就会收到一个when 。BadParcelableException我试过打电话Bundle.setClassLoader,但错误仍然存​​在。

支持主屏幕快捷方式的启动器是否有限制?

public class Foo implements Parcelable {

    public String title;

    private Foo(Parcel in) {
        title = in.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(title);
    }

    public static final Parcelable.Creator<Foo> CREATOR = new Parcelable.Creator<Foo>() {

        @Override
        public Foo createFromParcel(Parcel in) {
            return new Foo(in);
        }

        @Override
        public Foo[] newArray(int size) {
            return new Foo[size];
        }

    };

}

public static void installShortcut(Context context, Foo foo) {
    final Bundle args = new Bundle();
    args.setClassLoader(Foo.class.getClassLoader());
    args.putParcelable(EXTRA_FOO, foo);
    final Intent detail = new Intent(context, FooActivity.class);
    detail.putExtras(args);

    final Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, detail);
    ...
    context.sendBroadcast(shortcut);
}
4

0 回答 0