Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8892207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:56:29+00:00 2026-06-14T22:56:29+00:00

I have a GCM notification implementation which works perfectly. But, the problems is once

  • 0

I have a GCM notification implementation which works perfectly. But, the problems is once the message has been received in the intent in the received method, the message shown is always the old message. That is the the ‘ extras.getString(“payload”) ‘ always shows the old message. I can’t seem to figure out what the problem is.

The class which sends the GCM notification is :

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class C2DMMessageReceiver extends BroadcastReceiver {
            @Override
            public void onReceive(Context context, Intent intent) {
                            String action = intent.getAction();
                            Log.w("C2DM", "Message Receiver called");
                            if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
                                            Log.w("C2DM", "Received message");
                                            String payload = intent.getStringExtra("payload");
                                            Log.d("C2DM", "dmControl: payload = " + payload);
                                            // TODO Send this to my application server to get the real data
                                            // Lets make something visible to show that we received the message
                                            createNotification(context, payload);
                            }
            }



            public void createNotification(Context context, String payload) {
                           NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                            Notification notification = new Notification(R.drawable.icon,
                                                            "Message sent!", System.currentTimeMillis());
                            // Hide the notification after its selected
                            //notification.flags |= Notification.FLAG_AUTO_CANCEL;
                            notification.ledARGB = 0xff00ff00;
                            notification.ledOnMS = 300;
                            notification.ledOffMS = 1000;
                            notification.flags |= Notification.FLAG_SHOW_LIGHTS;


                            Intent intent = new Intent(context, MessageReceivedActivity.class);
                            intent.putExtra("payload", payload);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.putExtra("NotifID", 1);
                            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,intent, 0);
                            notification.setLatestEventInfo(context, "Message","Message Recieved", pendingIntent);
                            notificationManager.notify(0, notification);
            }

}

The class which recieves the notification message is:

import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.TextView;

public class MessageReceivedActivity extends Activity {
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                            setContentView(R.layout.activity_result);
                            NotificationManager notificationManager = (NotificationManager) this
                                                            .getSystemService(Context.NOTIFICATION_SERVICE);
                            //---cancel the notification---
                            int id=getIntent().getExtras().getInt("NotifID");
                            notificationManager.cancelAll();       
                            Bundle extras = getIntent().getExtras();
                            if (extras != null) {
                                            String message = extras.getString("payload");
                                            if (message.equals("call")) {
                                                            Intent intent = new Intent(Intent.ACTION_CALL);
                                                            intent.setData(Uri.parse("tel:9916261960"));
                                                            startActivity(intent);
                                            } else if (message.equals("camera")) {
                                                            Intent cameraIntent = new Intent(
                                                                                            MediaStore.ACTION_IMAGE_CAPTURE);
                                                            startActivity(cameraIntent);
                                            } else {
                                                            if (message != null && message.length() > 0) {
                                                                            TextView view = (TextView) findViewById(R.id.result);
                                                                            view.setText(message);
                                                            }
                                            }
                            }
                            super.onCreate(savedInstanceState);
            }

}

Here, the extras.getString(“payload”); holds the first time sent notification message always.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:56:31+00:00Added an answer on June 14, 2026 at 10:56 pm

    When creating your pending intent, use the FLAG_UPDATE_CURRENT

    PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    

    Otherwise the old intent is reused without the new extras

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have migrated my app to use the new GCM push system. It works
I am trying to use TextToSpeech but i have some strange problems. Let me
Have a simple one-off tasks which needs a progress bar. OpenSSL has a useful
I have made an application which is using GCM push messaging framework for getting
I am trying to send a message through GCM (Google Cloud Messaging). I have
I have developed a GCM application, where a server app sends notification to the
Hey I have been following gcm tutorial to create gcm-demo-server and a demo-client. All
I have a GCM Service that I want to create an Intent chooser (with
I try to implement GCM in my project and have problems with onMessage function.
I was trying to use GCM to have push-notification in my app. I called

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.