gpt4 book ai didi

android - 子 Activity 完成后无法调用 onactivityresult 函数

转载 作者:行者123 更新时间:2023-11-30 04:18:40 24 4
gpt4 key购买 nike

我正在使用以下代码。

 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();
}
}
});
}

问题是,当 Activity 结束时...并且我通过了这张收据,在我之前的类(class)中我将此 Activity 称为 public synchronized void onActivityResult 从不工作。

后退按钮也没有结束 Activity 。

请告诉我哪里错了,

最好的问候

最佳答案

这里是你的问题的解决方案

@Override
public void finish() {
Intent data = new Intent();
data.putExtra("receiptList", receipts);
setResult(Activity.RESULT_OK, data);
super.finish();
}

关于android - 子 Activity 完成后无法调用 onactivityresult 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9579494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com