Android chat application message notification receive issue
-
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);
-
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);