title: Android - Firebase - Send Users to Chat Room
body: <p><strong>Aim</strong></p>
  
  <p>Allowing the Users to access their selected Group Chat. Once the user clicks on the Group Chat name, they will be entered into that Group Chat.</p>
  
  <p><strong>Database Tree</strong></p>
  
  <p><a href="https://i.stack.imgur.com/HQdTe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HQdTe.png" alt="enter image description here"></a></p>
  
  <p>As shown in the Database Tree, the Currently Signed In user will be shown a list of Group Chat names that have been created. </p>
  
  <p>I have an Admin Account to create these Group Chats for the users.</p>
  
  <p>The Android, Asia, and Europe group chats that are seen within the Database ARE NOT fixed variables. They are names. A newly Group Chat name could be "Earth".</p>
  
  <p>Therefore there is no way of calling it by a variable other than calling it by the Node itself.</p>
  
  <p><strong>Screenshot of Application</strong></p>
  
  <ol>
  <li>List of Group Chats 2. Entering a Group Chat</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/66oNdm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/66oNdm.png" alt="image2"></a> <a href="https://i.stack.imgur.com/H4mdc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H4mdc.png" alt="image3"></a></p>
  
  <p><strong>Flow of Activities</strong></p>
  
  <ol>
  <li><p>GroupFragment ---> Chat Activity</p></li>
  <li><p>GroupFragment &lt;--- Chat Activity</p></li>
  </ol>
  
  <p><strong>Flow of Application</strong></p>
  
  <p>User--->LoginActivity--->UserActivity--->GroupFrag--->GroupChatActivity</p>
  
  <p>At the (GroupFrag--->GroupChatActivity) The user must select a Group Chat name within the GroupFrag to enter the GroupChatActivity</p>
  
  <p>The user must select a Group Chat name within the GroupFrag to enter the GroupChatActivity</p>
  
  <p><strong>Description</strong></p>
  
  <ol>
  <li>The users will be able to select a Group Chat name (from GroupFragment) and the app will bring the user into the Group Chat itself (into Chat Activity). The User will be able to go back to the GroupFragment and select another desired Group. </li>
  </ol>
  
  <p>(Group Chat names are <strong>NOT FIXED</strong> -- They're not a node that can be called from)</p>
  
  <p><strong>Problem</strong></p>
  
  <ol>
  <li>I am unable to select the Group Chat names after it was prompt within the Fragment, which will then bring me to the Group Chat. </li>
  </ol>
  
  <p><strong>Group Fragment</strong></p>
  
  <pre><code> @Override
      public void onStart() {
          super.onStart();
  
  
          class GroupAdapter extends RecyclerView.Adapter&lt;GroupAdapter.MyHolder&gt; {
  
              ArrayList&lt;String&gt; list;
  
              public GroupAdapter(ArrayList&lt;String&gt; list) {
                  this.list = list;
              }
  
  
              @Override
              public GroupAdapter.MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                  View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_groups, parent, false);
  
                  return new MyHolder(view);
              }
  
              @Override
              public void onBindViewHolder(MyHolder holder, int position) {
                  holder.setText(list.get(position));
              }
  
              @Override
              public int getItemCount() {
                  return list.size();
              }
  
              class MyHolder extends RecyclerView.ViewHolder {
                  TextView nameTextView;
  
                  public MyHolder(View itemView) {
                      super(itemView);
                      nameTextView = itemView.findViewById(R.id.groupChatNameTxt);
                  }
  
                  public void setText(String groupName) {
                      nameTextView.setText(groupName);
                  }
              }
          }
  
          jGroupsDatabase.addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
                  ArrayList&lt;String&gt; groupChatNames = new ArrayList&lt;&gt;();
                  for (DataSnapshot child : dataSnapshot.getChildren()) {
                      groupChatNames.add(child.getKey());
                  }
                  GroupAdapter adapter = new GroupAdapter(groupChatNames);
                  jGroupChatList.setAdapter(adapter);
  
                  //I'm not sure where to write a code for userID
                  //final String usersID = getRef(position).getKey();
  // When the user clicks on one of the group chat names, he/she will be sent to the Chat Activity
  
                  jGroupChatList.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          Intent intentUserProfile = new Intent(getActivity(), ChatActivity.class);
                          intentUserProfile.putExtra("groupChatName",groupName);
                          intentUserProfile.putExtra("neighbourhood", neighbourhood);
                          intentUserProfile.putExtra("usersName", usersName);
                          intentUserProfile.putExtra("usersID", usersID);
                          startActivity(intentUserProfile);
                      }
                  });
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
              }
          });
      }
  </code></pre>
  
  <p><strong>Chat Activity</strong></p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_chat);
  
          jGroupChatName = getIntent().getExtras().get("groupChatName").toString();
          jUserID = getIntent().getExtras().get("usersID").toString();
          jUserName = getIntent().getExtras().get("usersName").toString();
          jUserNeighbourhood = getIntent().getExtras().get("neighbourhood").toString();
  
          jChatRoot = FirebaseDatabase.getInstance().getReference().child(jGroupChatName);
  
          jChatToolbar = (Toolbar) findViewById(R.id.allUSersToolBar);
          setSupportActionBar(jChatToolbar);
          getSupportActionBar().setTitle(jGroupChatName); // Show the name of the selected group name
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          }
  </code></pre>
  
  <p><strong>Additional Comments</strong></p>
  
  <ul>
  <li>Online Tutorial</li>
  </ul>
  
  <p>I have watched an Android Firebase Group Chat tutorial on youtube. The link is <a href="https://www.youtube.com/watch?v=wVCz1a3ogqk" rel="nofollow noreferrer">https://www.youtube.com/watch?v=wVCz1a3ogqk</a>. But it does not provide some the features/ functions whic I am trying to implement.</p>
  
  <ul>
  <li>Linked Question</li>
  </ul>
  
  <p><a href="https://stackoverflow.com/questions/46412882/android-firebase-prompting-group-chat-names?noredirect=1&amp;lq=1">Android - Firebase - Prompting Group Chat Names</a></p>
  
  <p><strong>Future Implementations</strong></p>
  
  <p>For future implementations, I would like to send and retrieve the messages and prompt it into the group chat for the users to view like a real group chat. But of course, I will leave that for another Question.</p>