我想致电activity
获取结果。使用调用activity
中的按钮,没问题,但我想从对话框中调用子活动:
public class AddDialog extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setNeutralButton("Add", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_NEUTRAL) {
Intent intent = new Intent(getActivity(), AddActivity.class);
startActivityForResult(intent, 0);
}
}
});
调用子活动并按预期关闭,但不调用onActivityResult
。
是因为从startActivityForResult
调用了Fragment
吗?
答案 0 :(得分:1)
而不是startActivityForResult(intent, 0);
使用:
getActivity().startActivityForResult(intent, 0);
看看它是否有效。