Alertdialog In Andengine
I am trying to show a alertdialog but i keep getting this error 01-24 21:52:45.640: E/AndroidRuntime(31119): FATAL EXCEPTION: UpdateThread 01-24 21:52:45.640: E/AndroidRuntime(3111
Solution 1:
Call showDialog from the UIThread.
this.runOnUiThread(new Runnable() {
    @Override
    publicvoidrun() {
        MyActivity.this.showDialog(MY_DIALOG_ID);
    }
});
Oh and NO, NO, NO, NO, NO, NO, NO, NO:
case 1:
Solution 2:
It seems like, for some reason, the method onCreateDialog is called from the UpdateThread of AndEngine (While it should be called from the UI Thread).
Remember that when you show a dialog, you call showDialog(int id) rather than onCreateDialog(int id). After you call showDialog, Android will call onCreateDialog on the UI thread when possible.
In fact, I looked in showDialog info now and it is deprecated, it looks like there is a whole new way of creating dialogs. Read more here.
Solution 3:
try this
@Overrideprotected Dialog onCreateDialog(int id) {
  switch (id) {
  case1:
      isGameRunning = false;
      gameStarted = false;
      mEngine.stop();
      AlertDialog.Builderbuilder=newAlertDialog.Builder(this);
       builder.setTitle("How To Play")
              .setIcon(R.drawable.ic_launcher)
              .setPositiveButton("Thanks", newDialogInterface.OnClickListener() {
        publicvoidonClick(DialogInterface dialog, int id) {
            isGameRunning = true;
            mEngine.start();
            gameStarted = true;
        }
        });
      return builder.create();
  default:
      returnnull;
  }       
}
Post a Comment for "Alertdialog In Andengine"