GCM deleteToken throws MAIN_THREAD exception
<p>I have integrated <code>GCM</code> with my application. Registration of device is working good but I want to un-register device when user logs out. I am deleting token as </p>

<pre><code>new android.os.Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        InstanceID instanceID = InstanceID.getInstance(context);
                        try {
                            instanceID.deleteToken("project_id", GoogleCloudMessaging.INSTANCE_ID_SCOPE);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                });
</code></pre>

<p>But it is throwing exception:</p>

<p><strong>Exception</strong></p>

<pre><code> W/System.err: java.io.IOException: MAIN_THREAD
 W/System.err:     at com.google.android.gms.iid.InstanceID.zzb(Unknown Source)
 W/System.err:     at com.google.android.gms.iid.InstanceID.deleteToken(Unknown Source)
 W/System.err:     at pk.gov.pitb.ospc.util.AppUtil$1$1.run(AppUtil.java:129)
 W/System.err:     at android.os.Handler.handleCallback(Handler.java:730)
 W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:92)
 W/System.err:     at android.os.Looper.loop(Looper.java:137)
 W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5457)
 W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
 W/System.err:     at java.lang.reflect.Method.invoke(Method.java:525)
 W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:879)
 W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)
 W/System.err:     at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>Can anyone please help me out which is the missing thing?</p>

<p>Regards,</p>