我正在使用以下代码。
addNewReceipt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(), AddReceipt.class);
myIntent.putExtra("receiptList", receipts);
startActivityForResult(myIntent, RECEIPT_ADD);
}
});
}
@SuppressWarnings("unchecked")
public synchronized void onActivityResult(final int requestCode, int resultCode, final Intent data)
{
if (resultCode == Activity.RESULT_OK)
{
if (requestCode == RECEIPT_ADD)
{
receipts = (ArrayList<Receipt>) data.getSerializableExtra("receiptList");
addReceiptsInListView();
}
}
}
AddReceipt类的代码如下,
@Override
public void finish() {
Intent data = new Intent();
data.putExtra("receiptList", receipts);
setResult(RESULT_OK, data);
super.finish();
}
@SuppressWarnings("unchecked")
public void onCreateCall()
{
done.setOnClickListener(new OnClickListener()
{ //receiptAddBtn
@Override
public void onClick(View v)
{
String error = "";
Receipt receipt = new Receipt();
receipt.comments = comments.getText().toString();
receipt.referenceNo = receiptNo.getText().toString();
receipt.image = imageSelected;
if (receipt.image == null || receipt.referenceNo == "" )
{
error = "Please input Receipt No. and attach Image";
displayAlert(error);
}
else
{
receipts.add(receiptCounter,receipt);
finish();
}
}
});
}
问题是,当活动结束时......我通过这张收据,在我之前的课程中,我称之为此活动public synchronized void onActivityResult
永远不会有效。
后退按钮也没有结束活动。
请告诉我我哪里错了。
最好的问候
答案 0 :(得分:1)
以下是您问题的解决方案
@Override
public void finish() {
Intent data = new Intent();
data.putExtra("receiptList", receipts);
setResult(Activity.RESULT_OK, data);
super.finish();
}