0

我想在实现 Parcelable 的自定义类型的额外数据中发送带有意图的广播消息。

详细信息:我想在 HS 上创建快捷方式但是系统不接受我的自定义命令类型的对象,错误消息:android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.solvek.ussdfaster.entities.Command 当用户单击快捷方式时,此对象将被传递回我的应用程序。

    Intent shortcutIntent = new Intent(this, FormActivity.class);
    shortcutIntent.putExtra("command", command); // Note - commmand is my custom object
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, command.getTitle());
    Parcelable iconResource = Intent
        .ShortcutIconResource
        .fromContext(this,  R.drawable.ic_launcher);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");

    sendBroadcast(intent);
4

1 回答 1

0

对于 Command 类,我实现了 xml 序列化(使用 XStream)并将 Command 对象序列化为 String 作为 XML,然后传递给核心。不是完美的解决方案,但它现在有效。

于 2011-02-06T14:14:19.330 回答