title: RecyclerView returns null when activity is resumed
body: <p>I have a recyclerView, which works fine when activity is started. When from that activity I go to another and come back, the recyclerView is empty. It shows nothing, however sometimes it returns values but the layout is disturbed i.e there would be either gaps between the items or the layout will have a large gap from the top of the activity.</p>
  
  <p>The code for the class is:</p>
  
  <pre><code>public class product_page extends AppCompatActivity {
  
    FirebaseAuth mAuth;
    String s, product;
    ProgressDialog progressDialog;
    private RecyclerView recyclerView;
    FirebaseDatabase firebaseDatabase;
    DatabaseReference databaseReference;
    DatabaseReference db;
    FirebaseRecyclerAdapter&lt;ProductItemsConstructor, productViewHolder&gt; FirebaseAdapter;
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_product_page);
  
          Intent intent = getIntent();
          s = intent.getExtras().getString("pos");
          product = intent.getExtras().getString("product");
  
      mAuth = FirebaseAuth.getInstance();
      firebaseDatabase = FirebaseDatabase.getInstance();
      databaseReference = FirebaseDatabase.getInstance().getReference();
  
      RecyclerView.LayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
     // RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
      recyclerView = (RecyclerView) findViewById(R.id.recyclerView1);
      recyclerView.setHasFixedSize(true);
      recyclerView.setLayoutManager(layoutManager);
      recyclerView.setItemAnimator(new DefaultItemAnimator());
  
  
      Query query = firebaseDatabase.getReference().child("Products").child(s).child(product).orderByKey();
  
      FirebaseRecyclerOptions options = new FirebaseRecyclerOptions.Builder&lt;ProductItemsConstructor&gt;().setQuery(query,ProductItemsConstructor.class).build();
  
      FirebaseAdapter = new FirebaseRecyclerAdapter&lt;ProductItemsConstructor, productViewHolder&gt;(options) {
  
  
          @Override
          public productViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
              View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.product_items,parent,false);
              return new productViewHolder(view);
          }
  
          @Override
          protected void onBindViewHolder(@NonNull productViewHolder holder, int position, @NonNull ProductItemsConstructor model) {
              holder.Heading(model.getHeading());
              holder.Price(model.getPrice());
              holder.Prates(model.getPprice());
              holder.Rating(model.getRating());
              holder.setImg(getApplicationContext(),model.getImageUrl());
          }
      };
      recyclerView.setAdapter(FirebaseAdapter);
  
  }
  
  
  @Override
  protected void onStart() {
      super.onStart();
  
      FirebaseAdapter.startListening();
      recyclerView.setAdapter(FirebaseAdapter);
  }
  
  @Override
  protected void onStop() {
      super.onStop();
      FirebaseAdapter.stopListening();
  }
  
  @Override
  protected void onResume() {
      super.onResume();
  
      FirebaseAdapter.notifyDataSetChanged();
  }
  
  @Override
  public void onBackPressed() {
      super.onBackPressed();
      Intent in = new Intent(product_page.this, MainActivity.class);
      startActivity(in);
  }
  
  public class productViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  
      TextView head, rate, Prate, rating;
      ImageView img;
  
  
      public productViewHolder(final View itemView) {
          super(itemView);
          itemView.setOnClickListener(this);
      }
  
      private void Heading(String heading) {
          head = (TextView) itemView.findViewById(R.id.Pheading);
          head.setText(heading);
      }
  
      private void Price(String price) {
          rate = (TextView) itemView.findViewById(R.id.Pprice);
          rate.setText(price);
      }
  
      private void Prates(String prate){
          Prate = (TextView)itemView.findViewById(R.id.pRate);
          Prate.setText(prate);
      }
  
      private void Rating(String rting){
          rating = (TextView)itemView.findViewById(R.id.Rating);
          rating.setText(rting);
      }
  
      private void setImg(Context ctx, String img1) {
          img = (ImageView) itemView.findViewById(R.id.PImage);
          Picasso.with(ctx).load(img1).placeholder(R.drawable.notification).into(img);
          // progressDialog.dismiss();
      }
  }
  </code></pre>
  
  <p>This is the image when the activity is started first</p>
  
  <p><a href="https://i.stack.imgur.com/joopn.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>This is the image when activity is resumed</p>
  
  <p><a href="https://i.stack.imgur.com/ZJ4qJ.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>the log is shown below</p>
  
  <blockquote>
    <p>$ adb shell am start -n "com.strease.user.strease/com.strease.user.strease.SplashScreen" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
    Client not ready yet..Waiting for process to come online
    Connected to process 22007 on device motorola-moto_g__4_-ZY223L3X8L
    Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
    W/System: ClassLoader referenced unknown path: /data/app/com.strease.user.strease-2/lib/arm
    W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
    W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
    I/BiChannelGoogleApi: [FirebaseAuth: ] No Fallback module; NOT setting up for lazy initialization
    D/FirebaseAuth: Notifying id token listeners about user ( 1wU7rrZpvLRCJeXeRITJkIXTu492 ).
    D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
    V/FA: Cancelling job. JobID: 1598141556
    W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
    V/FA: Registered activity lifecycle callback
    I/FirebaseInitProvider: FirebaseApp initialization successful
    W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
    V/FA: onActivityCreated
    I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
    I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
    V/FA: Collection enabled
          App package, google app id: com.strease.user.strease, 1:841596997979:android:0ece7b89e3bda9c3
    I/FA: App measurement is starting up, version: 11910
          To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
          To enable faster debug mode event logging run:
            adb shell setprop debug.firebase.analytics.app com.strease.user.strease
    D/FA: Debug-level message logging enabled
    V/FA: Connecting to remote service
    V/FA: Connection attempt already in progress
    V/FA: Connection attempt already in progress
          Activity resumed, time: 33782085
    I/FA: Tag Manager is not found and thus will not be used
    D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=SplashScreen, firebase_screen_id(_si)=-132049841330100120}]
    D/FirebaseApp: Notifying auth state listeners.
    D/FirebaseApp: Notified 0 auth state listeners.
    I/Adreno: QUALCOMM build                   : 7d18700, I8ee426a9a2
              Build Date                       : 10/07/16
              OpenGL ES Shader Compiler Version: XE031.09.00.03
              Local Branch                     : mybranch22308589
              Remote Branch                    : quic/LA.BR.1.3.6_rb1.6
              Remote Branch                    : NONE
              Reconstruct Branch               : NOTHING
    V/FA: Connection attempt already in progress
    I/OpenGLRenderer: Initialized EGL, version 1.4
    D/OpenGLRenderer: Swap behavior 1
    D/FA: Connected to remote service
    V/FA: Processing queued up service tasks: 4
    V/FA: Recording user engagement, ms: 4017
    V/FA: Activity paused, time: 33786100
    D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=4017, firebase_screen_class(_sc)=SplashScreen, firebase_screen_id(_si)=-132049841330100120}]
    V/FA: onActivityCreated
    V/FA: onActivityCreated
    I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:6
    V/FA: Activity resumed, time: 33786801
    I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 6
    D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=SplashScreen, firebase_previous_id(_pi)=-132049841330100120, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-132049841330100119}]
    W/System: ClassLoader referenced unknown path: 
    W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/000000cd/n/armeabi-v7a
    W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/000000cd/n/armeabi
    W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms
    W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms
    D/FirebaseAuth: Notifying id token listeners about user ( 1wU7rrZpvLRCJeXeRITJkIXTu492 ).
    D/NetworkSecurityConfig: No Network Security Config specified, using platform default
    D/FirebaseApp: Notifying auth state listeners.
    D/FirebaseApp: Notified 1 auth state listeners.
    D/FirebaseAuth: Notifying id token listeners about user ( 1wU7rrZpvLRCJeXeRITJkIXTu492 ).
    D/FirebaseApp: Notifying auth state listeners.
    D/FirebaseApp: Notified 1 auth state listeners.
    W/ClassMapper: No setter/field for FCM Token found on class com.strease.user.strease.userInfoConstructor
                   No setter/field for Number found on class com.strease.user.strease.userInfoConstructor
                   No setter/field for Email found on class com.strease.user.strease.userInfoConstructor
    W/Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
    I/art: Do partial code cache collection, code=18KB, data=30KB
    I/art: After code cache collection, code=13KB, data=27KB
           Increasing code cache capacity to 128KB
    V/FA: Inactivity, disconnecting from the service
    V/FA: Session started, time: 33792791
    D/FA: Logging event (FE): session_start(_s), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-132049841330100119}]
    V/FA: Connecting to remote service
    D/FA: Connected to remote service
    V/FA: Processing queued up service tasks: 1
    V/FA: Inactivity, disconnecting from the service
    V/FA: Recording user engagement, ms: 23339
    V/FA: Connecting to remote service
    V/FA: Activity paused, time: 33810138
    D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=23339, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-132049841330100119}]
    V/FA: onActivityCreated
    V/FA: Connection attempt already in progress
    V/FA: Connection attempt already in progress
    V/FA: Activity resumed, time: 33810224
    D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=MainActivity, firebase_previous_id(_pi)=-132049841330100119, firebase_screen_class(_sc)=product_page, firebase_screen_id(_si)=-132049841330100118}]
    V/FA: Connection attempt already in progress
    D/FA: Connected to remote service
    V/FA: Processing queued up service tasks: 4
    I/art: Do partial code cache collection, code=42KB, data=62KB
    I/art: After code cache collection, code=42KB, data=62KB
           Increasing code cache capacity to 256KB
    V/FA: Inactivity, disconnecting from the service
    V/FA: Recording user engagement, ms: 10218
    V/FA: Connecting to remote service
    V/FA: Activity paused, time: 33820442
    D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=10218, firebase_screen_class(_sc)=product_page, firebase_screen_id(_si)=-132049841330100118}]
    V/FA: onActivityCreated
    I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
    V/FA: Connection attempt already in progress
    W/AllCapsTransformationMethod: Caller did not enable length changes; not transforming text
                                   Caller did not enable length changes; not transforming text
    I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
    V/FA: Connection attempt already in progress
          Activity resumed, time: 33821178
    D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=product_page, firebase_previous_id(_pi)=-132049841330100118, firebase_screen_class(_sc)=Checkout_page, firebase_screen_id(_si)=-132049841330100117}]
    V/FA: Connection attempt already in progress
    D/FA: Connected to remote service
    V/FA: Processing queued up service tasks: 4
    V/FA: Inactivity, disconnecting from the service
    V/FA: Recording user engagement, ms: 18503
    V/FA: Connecting to remote service
    V/FA: Activity paused, time: 33839680
    D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=18503, firebase_screen_class(_sc)=Checkout_page, firebase_screen_id(_si)=-132049841330100117}]
    V/FA: Connection attempt already in progress
          Connection attempt already in progress
    V/FA: Activity resumed, time: 33839706
    D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=Checkout_page, firebase_previous_id(_pi)=-132049841330100117, firebase_screen_class(_sc)=product_page, firebase_screen_id(_si)=-132049841330100118}]
    V/FA: Connection attempt already in progress
    D/FA: Connected to remote service
    V/FA: Processing queued up service tasks: 4
    V/FA: Inactivity, disconnecting from the service</p>
  </blockquote>
  
  <p>Any help or exlpanation would be appreciated
  Thanks.</p>