google cloud messaging - creating GCM client app, asynctask fails -


while creating gcm client application, asynctask giving compilation errors. oncreate calling registerbackgrouod check whether gcm instance running or not, if not create one.

but asyntask giving error : "asynctask cannot resolved type"

private void registerbackground() {     new asynctask() {         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;                 // should send registration id server on http,                 // can use gcm/http or ccs send messages app.                 // demo: don't need send because device                 // send upstream messages server echo message                 // using 'from' address in message.                  // save regid - no need register again.                 setregistrationid(context, regid);             } catch (ioexception ex) {                 msg = "error :" + ex.getmessage();             }             return msg;         }           protected void onpostexecute(string msg) {             mdisplay.append(msg + "\n");         }     }.execute(null, null, null); 

as observed alexbcn, , according documentation of asynctask, pass asynctask 3 types param. because want return payload of gcm push notification string, invoke asynctask<void, void, string>

so correct code snippet of gcm client is:

    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;                  // should send registration id server on http,                 // can use gcm/http or ccs send messages app.                 // demo: don't need send because device send                 // upstream messages server echo message using                 // 'from' address in message.                  // persist regid - no need register again.                 storeregistrationid(context, 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;         }.execute(null, null, null);     } 

Comments