I've noticed a difference between Android 7 (and before) and Android 8 (beta) when calling startActivityForResult from a DialogFragment.
In MainActivity below, when 'OK' is pressed on the dialog, it dismisses itself, creates and shows a new dialog, and calls startActivityForResult for AnotherActivity. AnotherActivity immediately finishes.
On Android 7, onActivityResult is called on the new dialog instance. On Android 8, onActivityResult is never called.
Can anyone explain this difference?
MCVE
public class MainActivity extends AppCompatActivity {
private static final String FRAGMENT_TAG = "tag";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
new SomeDialogFragment().show(getFragmentManager(), FRAGMENT_TAG);
}
public static class SomeDialogFragment extends DialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
super.onCreateDialog(savedInstanceState);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setPositiveButton(
"OK",
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface d, int which)
{
dismiss();
SomeDialogFragment dialog = new SomeDialogFragment();
dialog.show(getFragmentManager(), FRAGMENT_TAG);
startActivityForResult(new Intent(getActivity(), AnotherActivity.class), 7);
}
});
return builder.create();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
// Called on Android 7 but not Android 8.
}
}
}
and
public class AnotherActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setResult(1);
finish();
}
}