我有一个活动,其视图包含一个ListView,我使用了一个适配器来显示ListView中的项目。
ReceptionistListToEditActivity.java :
private ReceptionistListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_receptionist_list_to_edit);
ArrayList<ReceptionistViewModel> receptionists = getAllReceptionists();
adapter = new ReceptionistListAdapter(ReceptionistListToEdit.this,android.R.layout.simple_list_item_1, receptionists);
ListView receptionistListView = (ListView)findViewById(R.id.ReceptionistList);
receptionistListView.setAdapter(adapter);
}
从适配器我点击编辑按钮打开一个弹出窗口,该按钮出现在ListView的每个项目上。
ReceptionistListAdapter.java:
public static int RECEPTIONIST_SAVED = 1;
private void openEditReceptionistPopup(long receptionistId) {
Intent intent = new Intent(context, EditReceptionistPopup.class);
new DataLoadingProgressDialog(context).showDialog();
intent.putExtra("ReceptionistId", receptionistId);
((ReceptionistListToEditActivity)context).startActivityForResult(intent, RECEPTIONIST_SAVED);
}
关闭弹出窗口时,我想发送一些意图中的数据,我想在适配器中找到它。
EditReceptionistPopup.java
Intent intent = new Intent();
intent.putExtra(someData);
setResult(RESULT_OK, intent);
finish();
但是,活动类中的onActivityResult方法永远不会被调用。
ReceptionistListToEditActivity.java :
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == adapter.RECEPTIONIST_SAVED) {
ReceptionistViewModel viewModel = (ReceptionistViewModel) data.getSerializableExtra("receptionistDetails");
adapter.onActivityResult(viewModel);
}
}
我做错了什么?
答案 0 :(得分:2)
确保您尚未将manifest下的launchMode singleTask
添加到您已实施的活动onActivityResult()
编辑:
setResult(RESULT_OK, intent);
答案 1 :(得分:-1)
用以下替换你的openEditReceptionistPopup并试一试
在您的活动中公开上下文
使用公共上下文调用startActivityForResult
public static int RECEPTIONIST_SAVED = 1;
private void openEditReceptionistPopup(long receptionistId) {
Intent intent = new Intent(context, EditReceptionistPopup.class);
new DataLoadingProgressDialog(context).showDialog();
intent.putExtra("ReceptionistId", receptionistId);
context.startActivityForResult(intent, RECEPTIONIST_SAVED);
}