title: How do I clear recycler view items?
body: <p>I working on application were i have used recycler view to show data from firebase. When user gets logout the items in recycler view doesn't destroy.when some other user login he/she can see previous user data.</p>
  <p>How do i clear recycler view when user press logout button.I tried to clear all data from app but it closes the app and user needs to reclick the app.</p>
  <p>my adapter class.</p>
  <pre><code>public class UserHistoryViewAdapter extends RecyclerView.Adapter&lt;UserHistoryViewAdapter.UserHistoryViewHolder&gt;{
  private List&lt;UserHistoryModel&gt; userHistoryModels;
  private Dialog UserHistoryPopUp;
  private TextView bookingid_pop_up,check_in_date_time_pop_up,room_no, floor_no ,room_type;
  private Button close_btn;
  
  
  public void setUserHistoryModels(List&lt;UserHistoryModel&gt; userHistoryModels) {
      this.userHistoryModels = userHistoryModels;
  }
  
  @NonNull
  @Override
  public UserHistoryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.user_history,parent,false);
      UserHistoryPopUp = new Dialog(view.getContext());
      UserHistoryPopUp.setContentView(R.layout.user_history_pop_up);
      bookingid_pop_up = UserHistoryPopUp.findViewById(R.id.BookingId);
      check_in_date_time_pop_up = UserHistoryPopUp.findViewById(R.id.check_in_date_time_pop_up);
      room_no = UserHistoryPopUp.findViewById(R.id.Room_no_pop_up);
      floor_no = UserHistoryPopUp.findViewById(R.id.Floor_no_pop_up);
      room_type = UserHistoryPopUp.findViewById(R.id.Room_Type_pop_up);
      close_btn = UserHistoryPopUp.findViewById(R.id.Close_btn);
  
      return new UserHistoryViewHolder(view);
  }
  
  @Override
  public void onBindViewHolder(@NonNull UserHistoryViewHolder holder, final int position) {
      final String bookingid = userHistoryModels.get(position).getBookingId();
      final Timestamp check_in_d_t = userHistoryModels.get(position).getCheck_in_date_time();
      final SimpleDateFormat sdf = new SimpleDateFormat(&quot;dd/MM/yy HH:mm:ss&quot;);
      holder.bookingid.setText(bookingid);
      holder.showdetails.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              bookingid_pop_up.setText(bookingid);
              check_in_date_time_pop_up.setText(sdf.format(check_in_d_t.toDate()));
              room_no.setText(String.valueOf(userHistoryModels.get(position).getRoomNo()));
              floor_no.setText(String.valueOf(userHistoryModels.get(position).getFloorNo()));
              room_type.setText(userHistoryModels.get(position).getRoomType());
              UserHistoryPopUp.show();
              close_btn.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      UserHistoryPopUp.dismiss();
                  }
              });
  
          }
      });
  }
  
  @Override
  public int getItemCount() {
  
      if(userHistoryModels==null){
          return 0;
      }
      else {
  
      return userHistoryModels.size();}
  }
  
  public class UserHistoryViewHolder extends RecyclerView.ViewHolder {
      private TextView bookingid;
      private Button showdetails;
  
  
      public UserHistoryViewHolder(@NonNull View itemView) {
          super(itemView);
          bookingid = itemView.findViewById(R.id.Booking_id_textview);
          showdetails = itemView.findViewById(R.id.Show_booking_details);
  
      }
  
  
  
  }
  </code></pre>
  <p>}</p>
  <p>Here is my viewmodel class:</p>
  <pre><code>public class UserHistoryViewModel extends ViewModel implements FirebaseRespositary.OnFirestoreTaskCompleted {
  private MutableLiveData&lt;List&lt;UserHistoryModel&gt;&gt; UserHistoryData = new MutableLiveData&lt;List&lt;UserHistoryModel&gt;&gt;();
  private MutableLiveData&lt;Integer&gt; size1 = new MutableLiveData&lt;&gt;();
  
  
  
  
  public UserHistoryViewModel(){
  
  }
  
  public LiveData&lt;Integer&gt; getSize1(String emailId) {
      firebaseRespositary.getSize(emailId);
      return size1;
  }
  
  public LiveData&lt;List&lt;UserHistoryModel&gt;&gt; getUserHistoryData(String emaild) {
      firebaseRespositary.getData(emaild);
      return UserHistoryData;
  }
  
  
  private FirebaseRespositary firebaseRespositary = new FirebaseRespositary(this);
  
  @Override
  public void UserCheckedInDetails(List&lt;UserHistoryModel&gt; userHistoryViewModels) {
          UserHistoryData.setValue(userHistoryViewModels);
  }
  
  @Override
  public void FirestoreError(Exception e) {
  
  }
  
  @Override
  public void UserHistorySize(int size) {
      size1.setValue(size);
  }
  </code></pre>
  <p>}
  Here is my observer:</p>
  <pre><code>final String currentuser = firebaseAuth.getCurrentUser().getEmail();
     final UserHistoryViewModel userHistoryViewModel = new ViewModelProvider(getActivity()).get(UserHistoryViewModel.class);
      userHistoryViewModel.getSize1(currentuser).observe(getViewLifecycleOwner(), new Observer&lt;Integer&gt;() {
          @Override
          public void onChanged(final Integer integer) {
              if(integer!=0){
                  no_data_progressbar.setVisibility(View.VISIBLE);
                  userHistoryViewModel.getUserHistoryData(currentuser).observe(getViewLifecycleOwner(), new Observer&lt;List&lt;UserHistoryModel&gt;&gt;() {
                      @Override
                      public void onChanged(List&lt;UserHistoryModel&gt; userHistoryModels) {
                          no_data_progressbar.setVisibility(View.VISIBLE);
                          if(integer!=0) {
                              if (userHistoryModels.size() != 0) {
                                  no_data_progressbar.setVisibility(View.INVISIBLE);
                                  no_data.setVisibility(View.INVISIBLE);
                                  check_data.setVisibility(View.INVISIBLE);
                                  userHistoryModelList.addAll(userHistoryModels);
                                  userHistoryViewAdapter.setUserHistoryModels(userHistoryModelList);
                                  
                              }
                          }
  
                      }
                  });
              }else{
                  userHistoryModelList.clear();
                  userHistoryViewAdapter.notifyDataSetChanged();
                  no_data_progressbar.setVisibility(View.INVISIBLE);
                  no_data.setVisibility(View.VISIBLE);
                  check_data.setVisibility(View.VISIBLE);
  
              }
          }
      });
  </code></pre>
  <p>logout function:</p>
  <pre><code>    private void Logout() {
          if(network.isConnectingToInternet()){
  //            if (Build.VERSION_CODES.KITKAT &lt;= Build.VERSION.SDK_INT) {
  //                ((ActivityManager) getContext().getSystemService(ACTIVITY_SERVICE))
  //                        .clearApplicationUserData();
  //                return;
  //            }
              no_data_progressbar.setVisibility(View.VISIBLE);
              userHistoryModelList.clear();
              userHistoryViewAdapter.notifyDataSetChanged();
              no_data_progressbar.setVisibility(View.INVISIBLE);
  
          Toast.makeText(getContext(),&quot;Sign out&quot;,Toast.LENGTH_SHORT).show();
          firebaseAuth.signOut();
  
          navController.navigate(R.id.action_mainpage_to_loginscreen);
                  }
          else {
              new AlertDialog.Builder(getActivity())
                      .setTitle(&quot;No Internet&quot;)
                      .setMessage(&quot;Please connect to Internet first.&quot;)
                      .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int which) {
                              getActivity().finish();
                          }
                      })
                      .setIcon(android.R.drawable.ic_dialog_alert)
                      .show();
          }
  
      }
  </code></pre>