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 9099627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:39:52+00:00 2026-06-17T00:39:52+00:00

Please apologize if my question is too simple. Currently I am working on an

  • 0

Please apologize if my question is too simple.

Currently I am working on an android app, in which I will receive multiple alerts (from a server) and I have to view all push alerts one after the another (in the mobile notifications list).

I have given my code below. My server is sending all GCM push alert notifications to my android phone successfully.

However, I was able to view only the push alert which was sent last (in the notifications list). That is, consider my server is sending 2 push alerts: PUSH_A and PUSH_B. In my android phone, I was able to view only the 2nd alert: PUSH_B.

Can you please say, what I have done wrong. I have to view all push alerts in mobile one after the another (PUSH_A and PUSH_B in Notifications list).

My server code is as follows:

Sender aGcmSender = new Sender(API_KEY); 

//Constructing message which need to be transmitted to android device.      
Message aMessage = new Message.Builder().addData("message", thePushMsg).build(); 

Result aResult = aGcmSender.send(aMessage, theRegId, 1); //Transmitting message to android device
if(aResult != null)
{
    if(aResult.getMessageId() != null)
    {
        String aCanonicalRegistrationId = aResult.getCanonicalRegistrationId();
        if(aCanonicalRegistrationId != null)
        {
            //updating aCanonicalRegistrationId to my database
        }
        itsLogger.info("Push notification successfully sent to cub of phone: "+theCubsPhone);
        itsLogger.info("Message Id:"+aResult.toString());
    }
    else 
    {  
        String error = aResult.getErrorCodeName();
        itsLogger.info("Android Push Notification: Failed to send push notification to phone" + thePushMsg);
        if (error.equals(Constants.ERROR_NOT_REGISTERED)) {    
            // application has been removed from device - unregister database
        }
    }
}

GCM code in mobile:
*AndroidManifest.xml:*

 <permission android:name="MyProjectPackage.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="MyProjectPackage.permission.C2D_MESSAGE" />

<!-- App receives GCM messages. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
    <uses-permission android:name="android.permission.READ_OWNER_DATA" />
    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <!-- Permission to vibrate -->
    <uses-permission android:name="android.permission.VIBRATE" />

<!-- BroadcastReceiver for push alert notifications -->
        <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
          <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="MyProjectPackage" />
          </intent-filter>
        </receiver>
        <service android:name=".GCMIntentService" />

GCMIntentService:

private void sendGCMIntent(final Context theContext, String theMessage) 
    {   
    int icon = R.drawable.icon;
        long when = System.currentTimeMillis();

        NotificationManager notificationManager = (NotificationManager)
                theContext.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, theMessage, when);

        String title = theContext.getString(R.string.app_name);

        Intent notificationIntent = new Intent();
        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent =
                PendingIntent.getActivity(theContext, 0, notificationIntent, 0);
        notification.setLatestEventInfo(theContext, title, theMessage, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        // Play default notification sound
        notification.defaults |= Notification.DEFAULT_SOUND;

        // Vibrate if vibrate is enabled
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notificationManager.notify(0, notification);    
    }

Any help please.

Thank You.

  • 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-17T00:39:54+00:00Added an answer on June 17, 2026 at 12:39 am

    Because your notification id is 0 always

    notificationManager.notify(0, notification);
    

    The new notification will be replaced with the previous one. Just you have to change the id to any number like that :

    if (theMessage.equals(PUSH_A ))
        notificationManager.notify(0, notification);
    else
        notificationManager.notify(1, notification);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to android. So please apologize if my question is simple and
I apologize if this question is too generic, if it is please feel free
I am new to android development and so please apologize if my question is
I am currently developing my first android application, which is actually my first contact
Please apologize for the basicness of my question, but this is driving me crazy
Please help me figure this out. I apologize if this is a duplicate question,
I apologize if the same question was asked already. I just couldn't find. Please
I apologize in advance if this is an incredibly dumb question... Currently I have
firstly, I apologize if my question sounds little confusing, I will try my best
I apologize if my question does not make sense. As you can see from

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.