Custom Parcelable object passed to core
-
28-09-2019 - |
Question
I want to send a broadcast message with intent within extra data of my custom type which implements Parcelable.
In more details: I want to create a shortcut on the HS
However system does not accept object of my custom Command type, error message: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.solvek.ussdfaster.entities.Command
This object will be passed back to my app when user clicks on the shortcut.
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);
Solution
For Command class I implemented xml serialization (using XStream) and serialized Command object to String as XML and then passed to core. Not perfect solution but it works for now.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow