create a static handler in your class where you are registering gcm
static Handler mHandler;
and in your oncreate
mHandler = new Handler()
{
public void handleMessage(android.os.Message msg)
{
super.handleMessage(msg);
if (msg.what == 0)
{
GCMRegistrar.unregister(context);
}
}
};
now send message to handler to unregister this gcm like this.
Message msg=MainActivity.mHandler.obtainMessage();
msg.what=0;
MainActivity.mHandler.sendMessage(msg);
and this will fire handler of your mainActivity to unregister gcm.
try it ll help you.