title: GoogleCloudMessaging APIs Implementing GCM Client
body: <p>hello i am following the official documentation of android to send the push notification as the old method is deprecated but im facing problem in implementing GCM Client</p>
  
  <pre><code>http://developer.android.com/google/gcm/client.html
  </code></pre>
  
  <p>the tutorial is written here, scroll down and see</p>
  
  <pre><code>private void registerInBackground()
  </code></pre>
  
  <p>when i write this function on my app it gives me this error</p>
  
  <pre><code>Syntax error on token "void", @ expected
  </code></pre>
  
  <p>i have googled it and i know the error now that this method is trying to create a method inside a method but still im confused because it is the official documentation i must have done something wrong, can anybody point out plz?
  here is the method on this tutorial:</p>
  
  <pre><code>private void registerInBackground() {
      new AsyncTask() {
          @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;
  
                  // You should send the registration ID to your server over HTTP,
                  // so it can use GCM/HTTP or CCS to send messages to your app.
                  // The request to your server should be authenticated if your app
                  // is using accounts.
                  sendRegistrationIdToBackend();
  
                  // For this demo: we don't need to send it because the device
                  // will send upstream messages to a server that echo back the
                  // message using the 'from' address in the message.
  
                  // Persist the regID - no need to register again.
                  storeRegistrationId(context, regid);
              } catch (IOException ex) {
                  msg = "Error :" + ex.getMessage();
                  // If there is an error, don't just keep trying to register.
                  // Require the user to click a button again, or perform
                  // exponential back-off.
              }
              return msg;
          }
  
          @Override
          protected void onPostExecute(String msg) {
              mDisplay.append(msg + "\n");
          }
      }.execute(null, null, null);
      ...
      /**
       * Sends the registration ID to your server over HTTP, so it can use GCM/HTTP
       * or CCS to send messages to your app. Not needed for this demo since the
       * device sends upstream messages to a server that echoes back the message
       * using the 'from' address in the message.
       */
      private void sendRegistrationIdToBackend() {
        // Your implementation here.
      }
  }
  </code></pre>
  
  <p>now see that sendRegistrationIdToBackend is inside a method itself, any help plz?</p>