Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. Android chat application message notification receive issue

Android chat application message notification receive issue

Scheduled Pinned Locked Moved Android
helpandroidcomtutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pavlex4
    wrote on last edited by
    #1

    I have created android chat application. When I send message it loops all messages through notification and then show the latest message instead of just showing newest message inside the notification!!!! How to fix this issue???

    public class Chat extends AppCompatActivity
    {
    LinearLayout layout;
    RelativeLayout layout_2;
    ImageView sendButton;
    EditText messageArea;
    ScrollView scrollView;
    Firebase reference1, reference2;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity\_chat);
    
        layout = (LinearLayout) findViewById(R.id.layout1);
        layout\_2 = (RelativeLayout)findViewById(R.id.layout2);
        sendButton = (ImageView)findViewById(R.id.sendButton);
        messageArea = (EditText)findViewById(R.id.messageArea);
        scrollView = (ScrollView)findViewById(R.id.scrollView);
    
        Firebase.setAndroidContext(this);
    
        reference1 = new Firebase("https://zipa1x.firebaseio.com/messages/" + UserDetails.username + "\_" + UserDetails.chatWith);
        reference2 = new Firebase("https://zipa1x.firebaseio.com/messages/" + UserDetails.chatWith + "\_" + UserDetails.username);
    
        sendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String messageText = messageArea.getText().toString();
    
                if(!messageText.equals("")){
                    Map map = new HashMap();
                    map.put("message", messageText);
                    map.put("user", UserDetails.username);
                    reference1.push().setValue(map);
                    reference2.push().setValue(map);
                    messageArea.setText("");
                }
            }
        });
    
        reference1.addChildEventListener(new ChildEventListener()
        {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
    
                for (DataSnapshot child: dataSnapshot.getChildren())
                {
                    Map map = dataSnapshot.getValue(Map.class);
                    String message = map.get("message").toString();
                    String userName = map.get("user").toString();
    
                    if (userName.equals(UserDetails.username))
                    {
                        addMessageBox("You:-\\n" + message, 1);
    
    L 1 Reply Last reply
    0
    • P Pavlex4

      I have created android chat application. When I send message it loops all messages through notification and then show the latest message instead of just showing newest message inside the notification!!!! How to fix this issue???

      public class Chat extends AppCompatActivity
      {
      LinearLayout layout;
      RelativeLayout layout_2;
      ImageView sendButton;
      EditText messageArea;
      ScrollView scrollView;
      Firebase reference1, reference2;

      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity\_chat);
      
          layout = (LinearLayout) findViewById(R.id.layout1);
          layout\_2 = (RelativeLayout)findViewById(R.id.layout2);
          sendButton = (ImageView)findViewById(R.id.sendButton);
          messageArea = (EditText)findViewById(R.id.messageArea);
          scrollView = (ScrollView)findViewById(R.id.scrollView);
      
          Firebase.setAndroidContext(this);
      
          reference1 = new Firebase("https://zipa1x.firebaseio.com/messages/" + UserDetails.username + "\_" + UserDetails.chatWith);
          reference2 = new Firebase("https://zipa1x.firebaseio.com/messages/" + UserDetails.chatWith + "\_" + UserDetails.username);
      
          sendButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  String messageText = messageArea.getText().toString();
      
                  if(!messageText.equals("")){
                      Map map = new HashMap();
                      map.put("message", messageText);
                      map.put("user", UserDetails.username);
                      reference1.push().setValue(map);
                      reference2.push().setValue(map);
                      messageArea.setText("");
                  }
              }
          });
      
          reference1.addChildEventListener(new ChildEventListener()
          {
              @Override
              public void onChildAdded(DataSnapshot dataSnapshot, String s) {
      
                  for (DataSnapshot child: dataSnapshot.getChildren())
                  {
                      Map map = dataSnapshot.getValue(Map.class);
                      String message = map.get("message").toString();
                      String userName = map.get("user").toString();
      
                      if (userName.equals(UserDetails.username))
                      {
                          addMessageBox("You:-\\n" + message, 1);
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Please provide some proper details, and explain exactly where the error occurs.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups