如果你的
Workorder
对象已经是
Serializable
类型,你可以很容易地将该对象传递到一个意图的
Bundle
中。要将对象保存到意图中,你需要执行以下操作:
intent.putExtra("SomeUniqueKey", [intance of workorder]);
并在另一个活动中加载:
Workorder workorder = (Workorder) intent.getSerializableExtra("SomeUniqueKey");
如果你正在使用
startActivityForResult
,那么它应该如下所示:
WorkorderListActivity.java:
Intent intent = new Intent(this, WorkorderDetailsActivity.class);
intent.putExtra("SomeUniqueKey", _workorder);
startActivityForResult(intent, [UniqueNumber]);
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == [UniqueNumber])
{
if (resultCode == RESULT_OK)
{
Workorder workorder = (Workorder) intent.getSerializableExtra("SomeUniqueKey");
}
}
}
WorkorderDetailsActivity.java:
public void onCreate(Bundle savedInstanceState)
{
Bundle bundle = getIntent().getExtras();
_workorder = (Workorder) bundle.getSerializable("SomeUniqueKey");
}
public void onBackPressed()
{
Intent intent = getIntent();
intent.putExtra("SomeUniqueKey", _workorder);
setResult(RESULT_OK, intent);
}
我相信这应该可以工作。