title: alert dialog not showing up when leaving app while toast does android
body: <p>I am using code from Bluetooth Chat sample application. I want while the user leaves the app, he should be able to receive data. So If I do this:</p>
  
  <pre><code> case MESSAGE_READ:
                  byte[] readBuf = (byte[]) msg.obj;
                  // construct a string from the valid bytes in the buffer
                  String readMessage = new String(readBuf, 0, msg.arg1);
                  mConversationArrayAdapter.add(mConnectedDeviceName+":  " + readMessage);
                  /***************************ADDED***************************/
                  System.out.println("Number is"+(int)(readMessage.charAt(0)));
  
                  /***************************ADDED***************************/
                  break;
  </code></pre>
  
  <p>I do see in the DDMS the println statement.</p>
  
  <p>If I do this:</p>
  
  <pre><code> case MESSAGE_READ:
                  byte[] readBuf = (byte[]) msg.obj;
                  // construct a string from the valid bytes in the buffer
                  String readMessage = new String(readBuf, 0, msg.arg1);
                  mConversationArrayAdapter.add(mConnectedDeviceName+":  " + readMessage);
                  /***************************ADDED***************************/
                  System.out.println("Number is"+(int)(readMessage.charAt(0)));
                 Toast.makeText(getApplicationContext(), "received!! "
                          + mConnectedDeviceName, Toast.LENGTH_SHORT).show();
  
                  /***************************ADDED***************************/
                  break;
  </code></pre>
  
  <p>I do see the toast message even if I leave the application and I am in other apps.</p>
  
  <p>Finally what I really want is no matter if my app is not running when I receive a specific data, open up a alert dialog, and if I press yes for example make something (i want to make an http request on yes, and on no be transfeered to my app.)</p>
  
  <p>This is my code:</p>
  
  <pre><code> case MESSAGE_READ:
                  byte[] readBuf = (byte[]) msg.obj;
                  // construct a string from the valid bytes in the buffer
                  String readMessage = new String(readBuf, 0, msg.arg1);
                  mConversationArrayAdapter.add(mConnectedDeviceName+":  " + readMessage);
                  /***************************ADDED***************************/
  
                  new AlertDialog.Builder(getApplicationContext())
                  .setTitle("Title")
                  .setMessage("Message")
                  .setPositiveButton("Yes",
                   new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int which) {
                            //make http request
                  }
               })
                  .setNegativeButton("No",
                            new DialogInterface.OnClickListener() {
                               // @Override
                                public void onClick(DialogInterface dialog, int which) {
                                     //open my app
                                 }
  
                            }).show();
  
  
                  /***************************ADDED***************************/
                  break;
  </code></pre>
  
  <p>And in that case when I leave my app, and receive data I get a force close. I suppose the argment getApplicationContext is wrong but I do not know what to use.</p>
  
  <p>Sollution: I used a Notification instead.</p>