title: onResume() not called when using ViewPager2 and Fragment
body: <p>I have <code>Main_Activity</code> inside of it a <code>ViewPager2</code> which contains 3 <code>Fragment</code>. So I'm trying to use <code>onResume()</code> on the <code>MainActivity</code> to check if the user is connected to the internet. If he's connected i will display an Ad view. but the <code>onResume()</code> called only the first time, and when the user change the fragment <code>onResume()</code> doesn't called.
  I think the reason why is because of the MainActivity lost its foucs. So is there anyway.</p>
  <p><strong>Main_Activity.xml</strong></p>
  <pre><code>&lt;com.google.android.material.tabs.TabLayout
          android:id=&quot;@+id/tab_layout&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;0dp&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintBottom_toTopOf=&quot;@id/guideline_v2&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          android:background=&quot;@color/black_action_bar&quot;
          app:tabTextColor=&quot;@color/gris&quot;
          app:tabGravity=&quot;fill&quot;
          app:tabMode=&quot;fixed&quot;
          app:tabMaxWidth=&quot;0dp&quot;
          app:tabSelectedTextColor=&quot;@color/green_org&quot;
          app:tabIndicatorColor=&quot;@color/green_org&quot;
          app:tabTextAppearance=&quot;@style/customfontstyle&quot;
          &gt;
          &lt;com.google.android.material.tabs.TabItem
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:text=&quot;IMAGES&quot; /&gt;
          &lt;com.google.android.material.tabs.TabItem
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:text=&quot;VIDEOS&quot; /&gt;
          &lt;com.google.android.material.tabs.TabItem
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:text=&quot;SAVED&quot; /&gt;
  
  
  
  
      &lt;/com.google.android.material.tabs.TabLayout&gt;
  
  
  
      &lt;androidx.viewpager2.widget.ViewPager2
          android:id=&quot;@+id/view_pager&quot;
          android:layout_width=&quot;match_parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@id/guideline_v2&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          android:layout_height=&quot;0dp&quot;/&gt;
  </code></pre>
  <p><strong>MainActivity.java</strong></p>
  <pre><code>FragmentManager fragmentManager = getSupportFragmentManager();
      pagerAdapter = new PagerAdapter(fragmentManager,getLifecycle());
      pagerAdapter.addFragment(new ImagesFragment());
      pagerAdapter.addFragment(new VideosFragment());
      pagerAdapter.addFragment(new SavedFragment());
      viewPager.setAdapter(pagerAdapter);
      
  
      tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
          @Override
          public void onTabSelected(TabLayout.Tab tab) {
              viewPager.setCurrentItem(tab.getPosition());
          }
  
          @Override
          public void onTabUnselected(TabLayout.Tab tab) {
  
          }
  
          @Override
          public void onTabReselected(TabLayout.Tab tab) {
  
          }
      });
  
      viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
          @Override
          public void onPageSelected(int position) {
              super.onPageSelected(position);
              tabLayout.selectTab(tabLayout.getTabAt(position));
          }
      });
  </code></pre>