Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple Dialogs, second not displaying
    text
    copied!<p>I'm trying to display a couple of dialogs when a button is pressed, one after the other, and can't get the second to display. The first one is simply a development stub to replace a validation process during development...</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { &lt;snip&gt; btnLogin.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { &lt;snip&gt; VerifyLogin(userName, password); } }); } </code></pre> <p>...and...</p> <pre><code>private void VerifyLogin(String userName, String password) { boolean ok = false; if ((userName.length() &gt; 0) &amp;&amp; (password.length() &gt; 0)) ok = DevStub(); // &lt;- Mimics server validation, allows dev. to choose success or not &lt;snip&gt; } </code></pre> <p>...and...</p> <pre><code>private boolean DevStub() { new AlertDialog.Builder(this) .setTitle("DEVELOPMENT") .setMessage("Login: Successful or Not") .setPositiveButton("Successful", &lt;snip&gt; ) .setNegativeButton("Not Successful", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { new AlertDialog.Builder(getApplicationContext()) .setTitle("Invalid Username/Password") .setMessage("Try Again or Recover your password") .setPositiveButton( &lt;snip&gt; ) .setNegativeButton( &lt;snip&gt; ) .show(); } }) .show(); return success; } </code></pre> <p>As I say, this is only while I develop the interface, then the DevStub() will be replaced by a real login validation but I'd like to understand what I've got wrong here. When I tap the "Not Successful" button i simply get an exception.</p> <p>I'm thinking it has something to do with the getApplicationContext() in the inner dialog but, then again, I don't know - any suggestions, please?</p> <p>Logcat:</p> <pre><code>E/SKIA(12620): FimgApiStretch:stretch failed D/AndroidRuntime(12620): Shutting down VM W/dalvikvm(12620): threadid=1: thread exiting with uncaught exception (group=0x40c581f8) E/AndroidRuntime(12620): FATAL EXCEPTION: main E/AndroidRuntime(12620): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application E/AndroidRuntime(12620): at android.view.ViewRootImpl.setView(ViewRootImpl.java:706) E/AndroidRuntime(12620): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:316) E/AndroidRuntime(12620): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:218) E/AndroidRuntime(12620): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:143) E/AndroidRuntime(12620): at android.app.Dialog.show(Dialog.java:278) E/AndroidRuntime(12620): at android.app.AlertDialog$Builder.show(AlertDialog.java:932) E/AndroidRuntime(12620): at com.mtbsoft.wud.LoginActivity$2.onClick(LoginActivity.java:62) E/AndroidRuntime(12620): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:168) E/AndroidRuntime(12620): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(12620): at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime(12620): at android.app.ActivityThread.main(ActivityThread.java:4514) E/AndroidRuntime(12620): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(12620): at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime(12620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993) E/AndroidRuntime(12620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760) E/AndroidRuntime(12620): at dalvik.system.NativeStart.main(Native Method) D/dalvikvm(12620): GC_CONCURRENT freed 148K, 4% free 13223K/13639K, paused 2ms+4ms </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload