In my chat App FriendsFragment is shwoing blank. If I want to reflect that then, I have run the app, open the Friends tab in my app and after Instant run in Android studio and it will reflect. If it will not, then I have to add Log statement anywhere in my FriendsFragment, and run Instant run with exctly the open tab of friendsfragmet.

Why I'm telling you to add Log statement is necessary because I found this bug that whenever I change something on my Friends Fragment and then run Instant run, then only it will show the Fragment part. And I have to do this every time, otherwise it won't show. Add Log statement and remove second time, or change tag or change message, do something that makes the changes, and must run Instant run (that Yellow symbol like booster).

NOTE: I'm still doing this thing, I observe this problem by myself and I also don't know why I have to change something every time to show this Fragment? I also built the similar fragment in this same app, but for that there is no problem! 

**FriendFragment**

```
package com.jimmytrivedi.lapitchat;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;

import de.hdodenhof.circleimageview.CircleImageView;

public class FriendsFragment extends Fragment {

    private RecyclerView FriendRecyclerView;
    private DatabaseReference databaseReference, UsersDatabaseReference;
    private FirebaseAuth mAuth;
    private String currentUID;
    private View MainView;

    public FriendsFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        MainView = inflater.inflate(R.layout.fragment_friend, container, false);
        FriendRecyclerView = MainView.findViewById(R.id.FriendRecyclerView);
        mAuth = FirebaseAuth.getInstance();

        if (mAuth.getCurrentUser() != null) {
            currentUID = mAuth.getCurrentUser().getUid();
            databaseReference = FirebaseDatabase.getInstance().getReference().child("Friends").child(currentUID);
            databaseReference.keepSynced(true);
            UsersDatabaseReference = FirebaseDatabase.getInstance().getReference().child("Users");
            UsersDatabaseReference.keepSynced(true);
        }

        FriendRecyclerView.setHasFixedSize(true);
        FriendRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
           Log.d("wihddiewd", "Is it going?");
        return MainView;
    }

    @Override
    public void onStart() {
        super.onStart();

        Query query = FirebaseDatabase.                                                                                                                                                                                                                                                                                                         getInstance()
                .getReference()
                .child("Friends")
                .limitToLast(50);

        FirebaseRecyclerOptions<Friends> options = new FirebaseRecyclerOptions.Builder<Friends>()
                .setQuery(query, Friends.class)
                .build();

        final FirebaseRecyclerAdapter<Friends, FriendsViewHolder> FriendsRecyclerViewAdapter = new
                FirebaseRecyclerAdapter<Friends, FriendsViewHolder>(options) {
                    @Override
                    protected void onBindViewHolder(@NonNull final FriendsViewHolder holder, int position, @NonNull Friends model) {
                        holder.setDate(model.getDate());

                        final String listUID = getRef(position).getKey();
                        UsersDatabaseReference.child(listUID).addValueEventListener(new ValueEventListener() {
                            @Override
                            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                                final String userName = dataSnapshot.child("Name").getValue().toString();
                                String thumbImage = dataSnapshot.child("thumbImage").getValue().toString();
                                String userOnline = dataSnapshot.child("Online").getValue().toString();

                                holder.setName(userName);
                                holder.setThumbImage(thumbImage, getContext());
                                holder.setUserOnline(userOnline);
                                holder.mView.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        CharSequence options[] = new CharSequence[]{"Open profile", "Send message"};

                                        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                                        builder.setTitle("Select Options");
                                        builder.setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                if (which == 0) {
                                                    Intent intent = new Intent(getContext(), ProfileActivity.class);
                                                    intent.putExtra("userID", listUID);
                                                    startActivity(intent);
                                                }

                                                if (which == 1) {
                                                    Intent intent = new Intent(getContext(), ChatActivity.class);
                                                    intent.putExtra("userID", listUID);
                                                    intent.putExtra("userName", userName);
                                                    startActivity(intent);
                                                }
                                            }
                                        });

                                        builder.show();
                                    }
                                });

                            }

                            @Override
                            public void onCancelled(@NonNull DatabaseError databaseError) {

                            }

                        });
                    }

                    @NonNull
                    @Override
                    public FriendsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.users_single_layout, parent, false);
                        return new FriendsViewHolder(view);
                    }
                };

        FriendRecyclerView.setAdapter(FriendsRecyclerViewAdapter);
        FriendsRecyclerViewAdapter.startListening();

    }

    public static class FriendsViewHolder extends RecyclerView.ViewHolder {

        View mView;

        public FriendsViewHolder(View itemView) {
            super(itemView);
            mView = itemView;
        }

        public void setDate(String date) {
            TextView userStatusView = mView.findViewById(R.id.userStatus);
            userStatusView.setText(date);
        }

        public void setName(String name) {
            TextView userNameView = mView.findViewById(R.id.userName);
            userNameView.setText(name);
        }

        public void setThumbImage(String thumbImage, Context context) {
            CircleImageView circleImageView = mView.findViewById(R.id.userImage);
            Picasso.get().load(thumbImage).placeholder(R.drawable.defaultimage)
                    .into(circleImageView);
        }

        public void setUserOnline(String online) {
            ImageView userOnline = mView.findViewById(R.id.online);
            if (online.equals("true")) {
                userOnline.setVisibility(View.VISIBLE);
            } else {
                userOnline.setVisibility(View.INVISIBLE);
            }
        }
    }
}

```

Update
------

I know this is weird bug. But basically when I open my app and in app firends tab (which is FriendsFragment.java), it is showing blank. So I tried to debug that is there any mistake on my code or not? But I didn't find. But while debugging time, when I go to my firends tab in my mobile app, and put any log statement in Android Studio (because when I add/remove something so Android Studio will understand that some changes made happen, and then I run Instant run(not normal run) then FriendFragment will reflect and it shows the user list.

And I have to do this every time, (means I have to add something/remove something, that consider changes for Android Studio) then only FriendsFragment will show the users list. And even if I not open my Friends tab, but open something else in app and than run (instant run) that is also not work! Only when I just go to friends tab (that time it is showing blank, but that is okay) and run Instant run, then only it will reflect.

**fragment\_friends.xml**

```
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FriendsFragment">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/FriendRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v7.widget.RecyclerView>

</RelativeLayout>

```

**users\_single\_layout.xml**

```
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/userImage"
        android:layout_width="64dp"
        android:layout_height="64dp"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="15dp"
        android:src="@drawable/defaultimage" />

    <TextView
        android:id="@+id/userName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/userImage"
        android:layout_marginStart="99dp"
        android:text="Display Name"
        android:textColor="#000000"
        android:textSize="18dp" />

    <TextView
        android:id="@+id/userStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/userName"
        android:layout_below="@+id/userName"
        android:text="User default Status"
        android:textSize="15dp" />

    <ImageView
        android:id="@+id/online"
        android:layout_width="8dp"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/userName"
        android:layout_marginLeft="10dp"
        android:layout_toEndOf="@+id/userName"
        android:visibility="invisible"
        android:src="@drawable/online" />

</RelativeLayout>

```

Another Fragment ChatFragment, which is similar to this and working pretty fine).

ChatFragment.java

```
package com.jimmytrivedi.lapitchat;

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;

import de.hdodenhof.circleimageview.CircleImageView;

public class ChatFragment extends Fragment {

    private RecyclerView ConversationList;
    private DatabaseReference ConversationRef, MessageRef, UserRef;
    private FirebaseAuth mAuth;
    private String currentUID;
    private View MainView;

    public ChatFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        MainView = inflater.inflate(R.layout.fragment_chat, container, false);
        ConversationList = MainView.findViewById(R.id.ConversationList);
        mAuth = FirebaseAuth.getInstance();
        currentUID = mAuth.getCurrentUser().getUid();

        ConversationRef = FirebaseDatabase.getInstance().getReference().child("Chat").child(currentUID);
        ConversationRef.keepSynced(true);

        UserRef = FirebaseDatabase.getInstance().getReference().child("Users");
        UserRef.keepSynced(true);

        MessageRef = FirebaseDatabase.getInstance().getReference().child("Messages").child(currentUID);

        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        layoutManager.setReverseLayout(true);
        layoutManager.setStackFromEnd(true);

        ConversationList.setHasFixedSize(true);
        ConversationList.setLayoutManager(layoutManager);

        return MainView;
    }

    @Override
    public void onStart() {
        super.onStart();
        Query conversationQuery = ConversationRef.orderByChild("timestamp");

        Query query = FirebaseDatabase.getInstance()
                .getReference()
                .child("Chat")
                .limitToLast(50);

        FirebaseRecyclerOptions<Conversation> options = new FirebaseRecyclerOptions.Builder<Conversation>()
                .setQuery(query, Conversation.class)
                .build();

        FirebaseRecyclerAdapter<Conversation, ConversationViewHolder> ConversationRecyclerViewAdapter = new
                FirebaseRecyclerAdapter<Conversation, ConversationViewHolder>(options) {
                    @Override
                    protected void onBindViewHolder(@NonNull final ConversationViewHolder holder, int position, @NonNull final Conversation model) {
                        final String listUID = getRef(position).getKey();

                        Query lastMessageQuery = MessageRef.child(listUID).limitToLast(1);

                        lastMessageQuery.addChildEventListener(new ChildEventListener() {
                            @Override
                            public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
                                String data = dataSnapshot.child("message").getValue().toString();
                                holder.setMassage(data, model.isSeen());
                            }

                            @Override
                            public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

                            }

                            @Override
                            public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {

                            }

                            @Override
                            public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

                            }

                            @Override
                            public void onCancelled(@NonNull DatabaseError databaseError) {

                            }
                        });

                        UserRef.child(listUID).addValueEventListener(new ValueEventListener() {
                            @Override
                            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                                final String userName = dataSnapshot.child("Name").getValue().toString();
                                String userThumb = dataSnapshot.child("thumbImage").getValue().toString();

                                if (dataSnapshot.hasChild("Online")) {
                                    String userOnline = dataSnapshot.child("Online").getValue().toString();
                                    holder.setUserOnline(userOnline);
                                }

                                holder.setName(userName);
                                holder.setUserImage(userThumb, getContext());

                                holder.mView.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        Intent intent = new Intent(getContext(), ChatActivity.class);
                                        intent.putExtra("userID", listUID);
                                        intent.putExtra("userName", userName);
                                        startActivity(intent);
                                    }
                                });
                            }

                            @Override
                            public void onCancelled(@NonNull DatabaseError databaseError) {

                            }
                        });

                    }

                    @NonNull
                    @Override
                    public ConversationViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.users_single_layout, parent, false);
                        return new ConversationViewHolder(view);
                    }
                };

        ConversationList.setAdapter(ConversationRecyclerViewAdapter);
        ConversationRecyclerViewAdapter.startListening();
    }

    public static class ConversationViewHolder extends RecyclerView.ViewHolder {

        View mView;

        public ConversationViewHolder(View itemView) {
            super(itemView);
            mView = itemView;
        }

        public void setMassage(String message, boolean isSeen) {
            TextView userStatusView = mView.findViewById(R.id.userStatus);
            userStatusView.setText(message);

            if (!isSeen) {
                userStatusView.setTypeface(userStatusView.getTypeface(), Typeface.BOLD);
            } else {
                userStatusView.setTypeface(userStatusView.getTypeface(), Typeface.NORMAL);
            }
        }

        public void setUserOnline(String online) {
            ImageView userOnlineView = mView.findViewById(R.id.online);

            if (online.equals("true")) {
                userOnlineView.setVisibility(View.VISIBLE);
            } else {
                userOnlineView.setVisibility(View.INVISIBLE);
            }
        }

        public void setName(String userName) {
            TextView userNameView = mView.findViewById(R.id.userName);
            userNameView.setText(userName);
        }

        public void setUserImage(String userThumb, Context context) {
            CircleImageView userImageView = mView.findViewById(R.id.userImage);
            Picasso.get().load(userThumb).placeholder(R.drawable.defaultimage).into(userImageView);
        }
    }
}

```

**Friends.java**

```
package com.jimmytrivedi.lapitchat;

public class Friends {

    public String date;

    public Friends() {
    }

    public Friends(String date) {
        this.date = date;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }
}

```

**SectionPagerAdapter.java**

```
package com.jimmytrivedi.lapitchat;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

class SectionsPagerAdapter extends FragmentPagerAdapter {
    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {

        switch (position) {
            case 0:
                RequestFragment requestFragment = new RequestFragment();
                return requestFragment;

            case 1:
                ChatFragment chatFragment = new ChatFragment();
                return chatFragment;

            case 2:
                FriendsFragment friendFragment = new FriendsFragment();
                return friendFragment;

            default:
                return null;
        }

    }

    @Override
    public int getCount() {
        return 3;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return "Requests";

            case 1:
                return "Chats";

            case 2:
                return "Friends";

            default:
                return null;
        }
    }
}

```

**MainActivity.java**

```
package com.jimmytrivedi.lapitchat;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.facebook.login.LoginManager;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ServerValue;

public class MainActivity extends AppCompatActivity {

    private FirebaseAuth mAuth;
    private FirebaseUser currentUser;
    private Toolbar toolbar;
    private ViewPager viewPager;
    private SectionsPagerAdapter sectionsPagerAdapter;
    private TabLayout tabLayout;
    private DatabaseReference UserDatabaseReference;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mAuth = FirebaseAuth.getInstance();
        currentUser = mAuth.getCurrentUser();

        if (currentUser == null) {
            sendTostart();
        } else {
            UserDatabaseReference = FirebaseDatabase.getInstance().getReference().child("Users").child(mAuth.getCurrentUser().getUid());
            UserDatabaseReference.child("Online").setValue("true");
        }

        viewPager = findViewById(R.id.viewPager);
        sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        viewPager.setAdapter(sectionsPagerAdapter);

        toolbar = findViewById(R.id.mainToolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("Home");

        tabLayout = findViewById(R.id.tabLayout);
        tabLayout.setupWithViewPager(viewPager);
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (currentUser != null) {
            UserDatabaseReference.child("Online").setValue(ServerValue.TIMESTAMP);
        }
    }

    private void sendTostart() {
        startActivity(new Intent(MainActivity.this, StartActivity.class));
        finish();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.main_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        super.onOptionsItemSelected(item);

        if (item.getItemId() == R.id.logout) {
            FirebaseAuth.getInstance().signOut();
            LoginManager.getInstance().logOut();
            sendTostart();
        }

        if (item.getItemId() == R.id.settings) {
            startActivity(new Intent(MainActivity.this, SettingsActivity.class));
        }

        if (item.getItemId() == R.id.allUsers) {
            startActivity(new Intent(MainActivity.this, UsersActivity.class));
        }

        return true;
    }
}

```