How to display AlertDialog inside Timer in Service Class?
<p>I want to show AlertDialog inside Timer in Service class and i am using following code : </p>

<pre><code>timer.scheduleAtFixedRate( new TimerTask() 
{
    private Handler updateUI = new Handler()
    {
        public void dispatchMessage(android.os.Message msg)
        {
            super.dispatchMessage(msg);
            try {                       
                fun();
            } catch (Exception e) {e.printStackTrace(); }    
        }
    };
    public void run() 
    { 
        try {
            updateUI.sendEmptyMessage(0);                   
        }catch (Exception e) {e.printStackTrace(); }
    }
}, 0,60000);

public void fun()
{
    AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(this);                      
    dlgAlert.setMessage("");
    dlgAlert.setTitle("");              
    dlgAlert.setPositiveButton("OK", null);
    dlgAlert.setCancelable(true);
    dlgAlert.create();
    dlgAlert.show();
}
</code></pre>

<p>and I am getting following error: </p>

<pre><code>03-14 13:14:36.879: WARN/WindowManager(60): Attempted to add window with non-application token WindowToken{43f606b0 token=null}.  Aborting.
03-14 13:14:36.879: WARN/System.err(817): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
03-14 13:14:36.889: WARN/System.err(817):     at android.view.ViewRoot.setView(ViewRoot.java:509)
03-14 13:14:36.889: WARN/System.err(817):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
03-14 13:14:36.889: WARN/System.err(817):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
03-14 13:14:36.899: WARN/System.err(817):     at android.app.Dialog.show(Dialog.java:241)
03-14 13:14:36.899: WARN/System.err(817):     at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
03-14 13:14:36.899: WARN/System.err(817):     at com.mobilelocalite.pkg.GPSServiceCellId.comparefromDb(GPSServiceCellId.java:373)
03-14 13:14:36.909: WARN/System.err(817):     at com.mobilelocalite.pkg.GPSServiceCellId$1$1.dispatchMessage(GPSServiceCellId.java:133)
03-14 13:14:36.909: WARN/System.err(817):     at android.os.Looper.loop(Looper.java:123)
03-14 13:14:36.909: WARN/System.err(817):     at android.app.ActivityThread.main(ActivityThread.java:4627)
03-14 13:14:36.909: WARN/System.err(817):     at java.lang.reflect.Method.invokeNative(Native Method)
03-14 13:14:36.909: WARN/System.err(817):     at java.lang.reflect.Method.invoke(Method.java:521)
03-14 13:14:36.909: WARN/System.err(817):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-14 13:14:36.920: WARN/System.err(817):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-14 13:14:36.920: WARN/System.err(817):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>Thanks in Advance.</p>
