找到了很多关于我的问题的帖子,但没有一个适合我。我有一个片段,我必须在其中调用startActivityForResult()
textview 点击。从那里,将打开一个活动,用户将在其中填写一些数据并将其提交到数据库。从那里,我必须传递一个包含结果代码的意图。但是片段中的 onActivityResult() 没有被调用。
我的片段中的代码
Intent in = new Intent(getActivity(), NetBarrelActivity.class);
in.putExtra(AppUtility.ORDER_ID, orderDAO.getOrderNum());
in.putExtra(AppUtility.TICKET_ID, 2);
startActivityForResult(in, AppUtility.REQUEST_CODE);
我活动中的代码
Double NetBarrels = crudeNetCalculator(GrossBarrels,
ProductObsTemp, ProductObsGravity, ProductBSW);
db.updateTank(OrderID, TicketTypeID, CarrierTicketNum,
TankNum, TankTypeID, ProductObsTemp,
ProductObsGravity, ProductBSW, GrossBarrels,
NetBarrels);
Intent in = new Intent();
setResult(RESULT_OK, in);
finish();
片段中的 onActivityResult:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityReslt called");
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case AppUtility.REQUEST_CODE:
if(resultCode == Activity.RESULT_OK){
if (mOrdersDAO.getTicketType().equals(AppUtility.NET_BARREL)) {
ArrayList<OrderTicketsDao> mOrderTicketsDaos = dbHandler
.getOrderTicket(mOrdersDAO.getOrderNum());
if (mOrderTicketsDaos != null && mOrderTicketsDaos.size() > 0) {
TankAdapter mTankAdapter = new TankAdapter(getActivity(),
mOrderTicketsDaos);
listTank.setAdapter(mTankAdapter);
mTankAdapter.notifyDataSetChanged();
}
}
}
break;
default:
break;
}
}
那么,如何使用结果代码将意图发送回我的片段?