title: Looking for the proper syntax to set setmaxlifecycle on my tabbed application
body: <p>I'm just a hack and a newbie...I've received a lot of good information on this site but can't seem to find the answer to setting the max life cycle of a fragment, such that when it is selected, the <code>onResume()</code> for that fragment is executed.</p>
  <p>I've created a simple 3-tab application from the help of youTube videos and haven't figured out to properly set the lifecycle. I'm not sure how much information I should include, so i'll start with this:</p>
  <pre><code>val tabLayout: TabLayout = findViewById(R.id.tab_layout)
  val viewPager: ViewPager = findViewById(R.id.view_pager)
  val viewPagerAdpater = ViewPagerAdapter(supportFragmentManager)
  
  viewPagerAdpater.addFragment(SummaryFragment(), &quot;Summary&quot;)
  viewPagerAdpater.addFragment(BoxFragment(), &quot;Box&quot;)
  viewPagerAdpater.addFragment(SettingsFragment(), &quot;Settings&quot;)
  
  viewPager.adapter = viewPagerAdpater
  tabLayout.setupWithViewPager(viewPager)
  </code></pre>
  <p>I've tried this, which crashes:</p>
  <blockquote>
  <p>supportFragmentManager.beginTransaction().setMaxLifecycle(viewPagerAdpater.getItem(1),Lifecycle.State.RESUMED)</p>
  </blockquote>
  <p>There is also this code:</p>
  <pre><code>internal class ViewPagerAdapter(fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager) {
  
      private val fragments: ArrayList&lt;Fragment&gt;
      private val titles: ArrayList&lt;String&gt;
  
      init{
          fragments = ArrayList&lt;Fragment&gt;()
          titles = ArrayList&lt;String&gt;()
      }
      
      override fun getItem(position: Int): Fragment {
          return fragments[position]
      }
  
      override fun getCount(): Int {
          return fragments.size
      }
  
      fun addFragment(fragment: Fragment, title: String){
         fragments.add(fragment)
          titles.add(title)
      }
  
      override fun getPageTitle(i: Int): CharSequence? {
          return titles[i]
      }
  }
  </code></pre>
  <p>Thanks and let me know if more information is required...</p>