Instead of startActivityForResult(intent, 0);
use:
getActivity().startActivityForResult(intent, 0);
And see if it works.
Question
i'd like to call an activity
for a result. With a button within the calling activity
it's no problem but i'd like to call the sub-activity from a dialog:
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);
}
}
});
The sub-activity is called and closed as expected but onActivityResult
isn't called.
Is it because startActivityForResult
is called from an Fragment
?
Solution
Instead of startActivityForResult(intent, 0);
use:
getActivity().startActivityForResult(intent, 0);
And see if it works.