I just published a game on the Play Store and am planning to make it look better and more intuitive, si I'm trying to replace the Android dialogs by mines.
When the user finish a level, I need my custom dialog to show and if the user clicks some buttons, the dialog (which is an activity with a custom theme that make it looks like a dialog) have to return an integer with setResult(customResult, intent)
and then finish.
The problem is that when I receive the resultCode in the onActivityResult()
of the activity that did startActivityForResult(intentCustomDialog, 0)
, I call a custom method that restart the level or launch the next one depending on the result (used to know what button the user clicked). This methods should also restarts the Chronometer, but it does nothing !!!!!!!
On the other side when I use the android dialog and I put the restart()
call in the onClickListener the chronometer is successfully restarted !?
So what am I missing ? Why the restart()
call successfully restart the chronometer with an onClickListener
of the android dialogs but not when I call it from the onActivityResult()
method ?
Would be very helpful so I could make my own dialogs implementation and use the onActivityResult()
or even call a custom onDialogResult()
method to separate startActivityForResult()
launches of custom dialogs activities and normal activities.
Thanks in advance.
EDIT
In my game class :
...
public static final int RESULT_RESTART = 8;
public static final int RESULT_NEXT = 9;
public static final int RESULT_MENU = 10;
...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (resultCode) {
case RESULT_MENU:
back(null);
break;
case RESULT_NEXT:
nextGrid();
break;
case RESULT_RESTART:
restartGrid();
break;
}
}
restartGrid() method :
public void restartGrid() {
...
startChrono();
...
}
public void startChrono() {
chrono.setBase(SystemClock.elapsedRealtime());
chrono.start();
}
Works perfectly from a DialogInterface.OnClickListener()
.