I\'m migrating my dialogs, currently using Activity.showDialog(DIALOG_ID);
, to use the DialogFragment
system as discussed in the android reference.
While André's solution works, a better solution is to get the updated activity during onAttach() in your Fragment
.
private DialogTestListener mListener;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mListener = (DialogTestListener) activity;
}
With this solution, you won't need to pass the Activity
in newInstance()
anymore. You just need to make sure the Activity
owning your Fragment
is a DialogTestListener
. You also don't need to save the state like in the ResultReceiver
solution.