android - Gcm unregistration -


i working on gcm in android. done registration of device gcm using following code registers device asynchronously.

private void registerinbackground() {         new asynctask<void, void, string>() {             @override             protected string doinbackground(void... params) {                 string msg = "";                 try {                     if (gcm == null) {                         gcm = googlecloudmessaging.getinstance(context);                     }                     regid = gcm.register(sender_id);                     msg = "device registered, registration id=" + regid;                      storeregistrationid(context, regid);                     msg="registration success. regid: "+regid;                 } catch (ioexception ex) {                     msg = "error :" + ex.getmessage();                     // if there error, don't keep trying register.                     // require user click button again, or perform                     // exponential back-off.                 }                 return msg;             }              @override             protected void onpostexecute(string msg) {                 log.e("gcm", msg);             }         }.execute(null, null, null);     } 

registration done in registrationactivity want unregister device. unregister command sent server app, received on android side. how can unregister device activity (mdmactivity) process received messages. whether should asyn or sync??

is wrong create object registrationactivity , calling unregisterinbackground function using object below mdmactivity?

 registrationactivity reg=new registrationactivity();  reg.unregisterinbackground(); 

and unregisterinbackground function in registrationactivity follows:

protected void unregisterinbackground() {         new asynctask<void, void, string>() {             @override             protected string doinbackground(void... params) {                 string msg = "";                 try {                     if (gcm == null) {                         gcm = googlecloudmessaging.getinstance(context);                     }                     gcm.unregister();                     msg = "device unregistered, registration id=" + regid;                      // delete regid                      deleteregistrationid(context, regid);                 } catch (ioexception ex) {                     msg = "error :" + ex.getmessage();                 }                 return msg;             }              @override             protected void onpostexecute(string msg) {                 log.e("unregistration", msg);             }         }.execute(null, null, null);     } 

need help!! in advance.

unregister() blocking, register(). such, need run in background thread similar way did asynctask.

you call on gcm instance, think it's fine call whichever activity long have gcm instance.

you might want read this before implementing unregister functionality.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -