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オブジェクトをXMLとしてStringにシリアル化してから、コアに渡しました。完璧な解決策ではありませんが、今のところは機能します。

于 2011-02-06T14:14:19.330 に答える