I have a GameActivity
Activity
one of whose methods is:
/** Show "Game is finished" dialog. */
public void showFinishedDlg(int bodyMsgRes) {
GameFinishedDlgFragment.newInstance(bodyMsgRes).show(
this.getFragmentManager(), "finished_dlg");
}
This is the dialog fragment that method creates:
public class GameFinishedDlgFragment extends DialogFragment {
static GameFinishedDlgFragment newInstance(int bodyMsgRes) {
GameFinishedDlgFragment frag = new GameFinishedDlgFragment();
Bundle bundle = new Bundle();
bundle.putInt("body_msg", bodyMsgRes);
frag.setArguments(bundle);
return frag;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle args = getArguments();
int bodyMsgRes = args.getInt("body_msg");
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(bodyMsgRes)
.setPositiveButton(R.string.new_game, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// PROBLEM HERE. TODO: Restart GameActivity
this.parentActivity.recreate();
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
I'm trying to make the onClick
of the dialog's button restart GameActivity
, but I can't figure out how to get the reference to that activity instance.
If I try:
this.parentActivity.recreate();
the compiler tells me:
Cannot resolve symbol 'parentActivity'