How to show alert dialog in home screen?
<p>I am trying to run alarm which make alert dialog run in home screen showing . i.e when the application is closed, and when the event time is reached, the alert dialog shows the title of the event and rings alarm infinitely. If the button in alert dialog is clicked, then the alarm goes off, My code is as follows:</p>

<pre><code>void doReminderWork(Intent intent) {
    ToDoApplicationActivity ap = new ToDoApplicationActivity();
    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Intent notificationIntent = new Intent(this, ToDoApplicationActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);

    Notification note = new Notification(R.drawable.alarm, "...Calendar Alarm...", System.currentTimeMillis());
    note.setLatestEventInfo(this,"Event : ", ap.title1, pi);

    note.defaults |= Notification.DEFAULT_SOUND;
    note.flags |= Notification.FLAG_AUTO_CANCEL;

    int id = 123456789;
    manager.notify(id, note);


   Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); 
    mMediaPlayer = new MediaPlayer();

    try {
        mMediaPlayer.setDataSource(this, alert);
    } catch (IllegalArgumentException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (SecurityException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IllegalStateException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    final AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

    if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0)
    {
               mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
               mMediaPlayer.setLooping(false);
               try 
               {
                   mMediaPlayer.prepare();
               }
               catch (IllegalStateException e) 
               {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) 
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            mMediaPlayer.start();

     }
</code></pre>

<p>After this if i give alert dialog code to stop media player, i know it cant stop playing the alarm. Here, even when the application is closed, i need to show the alert dialog. I m trying this for past 2 days.</p>

<p>I'm Getting Following Exception:</p>

<blockquote>
  <p>android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application</p>
</blockquote>

<p>Any help is highly appreciated and thanks in advance...</p>
