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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:03:32+00:00 2026-06-14T12:03:32+00:00

I am implementing a notification in my application ( xmpp chat ) with a

  • 0

I am implementing a notification in my application ( xmpp chat ) with a packet listener.

Till the time the first notification comes the code works fine, but as soon as the person clicks on the notification, then after the first click both the code of ( if and else ) is running out. I am not able to get the solution and its strange also HOW BOTH IF/ELSE code is running – AFTER FIRST NOTIFICATION CLICK.

code

PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
        final PacketCollector collector = connection.createPacketCollector(filter);
        connection.addPacketListener(new PacketListener() {
            public void processPacket(Packet packetChat) {
                Message message = (Message) packetChat;
                packetChat = collector.nextResult();

                if (message.getBody() != null) {

                    fromName = StringUtils.parseBareAddress(message
                            .getFrom());
                    Log.i("XMPPClient", "Got text [" + message.getBody()
                            + "] from [" + fromName + "]");
                    // messages.add(fromName + ":");
                    mMessageItem = new MessageItemDataClass();
                    mMessageItem.isSendMessage = false;
                    mMessageItem.messageText = message.getBody();
                    messages.add(mMessageItem);


                    //to add the packet message in the layout only when the user is on the same friend's screen
                    //for anonymous chat
                    if(packetChat.getFrom().equalsIgnoreCase(refineFromjId(frienduserID)+"/Smack")){



                        messages.add(mMessageItem);
                    }
                    else{
                        if(checkPresence=true){
                        notificationforChat(fromName.substring(0,fromName.indexOf("@"))+":1212 "+message.getBody(),packetChat.getFrom(),0);
                        }
                    }

                    //messages.add(mMessageItem);
                    // Add the incoming message to the list view
                    mHandler.post(new Runnable() {
                        public void run() {
                            //simply turn around to the last of the screen
                            mList.setSelection(mList.getCount());

                            lastIndex = mList.getLastVisiblePosition()+1;
                            if (mList.getFirstVisiblePosition() > lastIndex || mList.getLastVisiblePosition() <= lastIndex) {
                                //mList.smoothScrollToPosition(lastIndex);
                                customAdapter.notifyDataSetChanged();
                                mList.setSelection(mList.getCount());

                                dbhHelper.close();

                            }else{
                                mList.setSelection(mList.getCount());
                                customAdapter.notifyDataSetChanged();

                                dbhHelper.close();

                            }
                        }
                    });
                }
            }               
        }, filter);

Notification

public void notificationforChat(CharSequence message,String toJid, int notificationID) {

        int notificationCount = 1;
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
        int icon = R.drawable.ic_launcher;
        CharSequence tickerText = message;
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, tickerText, when);
        //notification.number = notificationCount++;
        Context context = getApplicationContext();



        CharSequence contentTitle = "Chat";
        CharSequence contentText = message;
        Intent notificationIntentforChat = new Intent(this, UserChatActivity.class);
        notificationIntentforChat.putExtra("userNameVal", toJid);       
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                notificationIntentforChat, PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setLatestEventInfo(context, contentTitle, contentText,
                contentIntent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.defaults = Notification.DEFAULT_ALL;   
        mNotificationManager.notify(notificationID, notification);
    }

Please help me if anybody can!
Thanks

  • 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-14T12:03:33+00:00Added an answer on June 14, 2026 at 12:03 pm

    Your function might be called more than once (may be twice) at the same time with different conditions…so you will be getting the feeling of if and else getting called. Try using a flag to limit the number of times that code block is executed or set a counter to check whether the code block is executed more than once. Make the counter or flag variable that you are planning to use as static so that you can detect the call from different instances that you might be creating unknowingly.

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

Sidebar

Related Questions

I'm implementing an windows phone 7 application with push notification. The push notification would
Hi i am new to android. I am implementing a code with notification functionality.
I am interested in implementing C2DM for the push notification feature in my application.
In my application i used Urban Airship for push Notification, But Urban Airship push
I am implementing a push notification in my application. Server: php Client: iphone Sever
I am implementing C2DM for push notification in an android application, it need at
In my application I am implementing the Push Notification Service. I have a Content
I am implementing a chat client in an application. Conversation windows are tabbed and
I am implementing a Push Notification server for our iPhone application. I am using
I am implementing a push notification service. I would need to create a database

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.