这是我的班级:
public class Asset extends BaseModel implements Serializable{...}
在活动中我有这个:
private void openAssignAssetIntent(String actionType){
Intent assignAssetIntent = new Intent(this,AssignAssetActivity.class);
assignAssetIntent.putExtra("currentAsset",currentAsset);
startActivity(assignAssetIntent);
}
我试图从另一个Activity获取此值(“currentAsset”),如下所示:
Asset asst = (Asset) getIntent().getSerializableExtra("currentAsset");
但我得到了这个例外:
java.lang.RuntimeException:Parcelable遇到编写可序列化对象的IOException
我做错了什么?
答案 0 :(得分:0)
改为使用Bundle
:
Bundle bundle = new Bundle();
bundle.putSerializable("currentAsset", currentAsset);
Intent assignAssetIntent = new Intent(this,AssignAssetActivity.class);
assignAssetIntent.putExtras(bundle);
startActivity(assignAssetIntent);
然后像
一样检索它Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
Asset asset = (Asset) bundle.getSerializable("currentAsset");
希望这会有所帮助