title: How to open BottomNavigationView's fragment in activity?
body: <p>I want to call method 
  <strong><em>showNewsPageTime()</em></strong> 
  from <strong>MainFragment.kt</strong> in AlertBoxActivity.kt to open 
  <strong>newsFragment</strong>, 
  but app has stopped.</p>
  
  <p><code>MainFragment.kt</code></p>
  
  <p>(<code>BottomNavigationView</code> located here. I want to open <code>NewsFragment</code> page from here, because if i'll open it directly bottom navigation disappears.)</p>
  
  <pre><code>package kz.app.fragment
  import android.annotation.SuppressLint
  import android.app.Activity
  import android.os.Bundle
  import android.support.design.widget.BottomNavigationView
  import android.support.v4.app.Fragment
  import android.support.v4.widget.DrawerLayout
  import android.support.v7.content.res.AppCompatResources
  import android.support.v7.view.SupportMenuInflater
  import android.view.Gravity
  import android.view.LayoutInflater
  import android.view.MenuItem
  import android.view.View
  import android.view.ViewGroup
  import kotlin.concurrent.schedule
  import android.view.inputmethod.InputMethodManager
  import kotlinx.android.synthetic.main.fragment_main.*
  import kotlinx.android.synthetic.main.fragment_main.view.*
  import kz.app.R
  import kz.app.model.MainViewModel
  import kz.app.model.Stat## Heading ##eViewModel
  import kz.app.repository.PreferencesRepository
  import kz.app.util.OnBackPressDelegate
  import kz.app.util.bind
  import kz.app.util.setBadge
  
  
  class MainFragment : Fragment(), BottomNavigationView.OnNavigationItemSelectedListener, OnBackPressDelegate, DrawerLayout.DrawerListener {
      private val model by lazy { StateViewModel.get&lt;MainViewModel&gt;(this) }
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          val imm = context?.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
          imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
          retainInstance = true
          if (!PreferencesRepository.getInstance(context
                          ?: return).isTutorialFinished.blockingFirst())
              InstructionFragment().show(childFragmentManager)
      }
  
      @SuppressLint("SetTextI18n")
      override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
          val view = inflater.inflate(R.layout.fragment_main, container, false)
          view.bottomNavigation.initMenu()
          view.bottomNavigation.setOnNavigationItemSelectedListener(this)
          view.toolbar.setNavigationOnClickListener { view.drawer.openDrawer(Gravity.START) }
          view.pickCity.setOnClickListener { _ -&gt; CityPickerDialogFragment.show(childFragmentManager) { model.setCurrentCity(it.id) } }
          view.pickCity.bind(model.currentCityIconResId) { setImageResource(it) }
          view.flipper.displayedChild = savedInstanceState?.getInt(KEY_CURRENT_ITEM, 0) ?: 0
          view.bottomNavigation.run {
              selectedItemId = menu.getItem(view.flipper.displayedChild).itemId
          }
          view.drawer.addDrawerListener(this)
          view.toolbar.setOnMenuItemClickListener {
              val currentPage = view?.flipper?.displayedChild
                      ?: return@setOnMenuItemClickListener false
              val shoppingFragment = childFragmentManager.findFragmentById(R.id.shoppingFragment)
              val newsFragment = childFragmentManager.findFragmentById(R.id.newsFragment)
              val bonusFragment = childFragmentManager.findFragmentById(R.id.bonusFragment)
              val notificationsFragment = childFragmentManager.findFragmentById(R.id.notificationsFragment)
              val helpFragment = childFragmentManager.findFragmentById(R.id.helpFragment)
              when (currentPage) {
                  0 -&gt; shoppingFragment.onOptionsItemSelected(it)
                  1 -&gt; newsFragment.onOptionsItemSelected(it)
                  2 -&gt; bonusFragment.onOptionsItemSelected(it)
                  3 -&gt; helpFragment.onOptionsItemSelected(it)
                  4 -&gt; notificationsFragment.onOptionsItemSelected(it)
                  else -&gt; false
              }
          }
  
  
          return view
      }
  
      fun showBonusesPage() {
          view?.flipper?.displayedChild = 2
          view?.bottomNavigation?.selectedItemId = R.id.bonus
      }
  
      fun showNewsPage() {
          view?.flipper?.displayedChild = 1
  
          view?.bottomNavigation?.selectedItemId = R.id.news
          System.out.println("HEloo")
      }
  //this method should be called in AlertBoxActivity
      fun showNewsPageTime() {
          var newsFragment = 1
          childFragmentManager.findFragmentById(R.id.newsFragment)
          InstructionFragment().show(childFragmentManager)
      }
  
  
  
  
      private fun BottomNavigationView.initMenu() {
          menu.clear()
          menu.add(0, R.id.main, 0, R.string.main).icon = AppCompatResources.getDrawable(context, R.drawable.ic_shopping)
          menu.add(0, R.id.news, 0, R.string.news).icon = AppCompatResources.getDrawable(context, R.drawable.ic_news)
          menu.add(0, R.id.bonus, 0, R.string.bonus).icon = AppCompatResources.getDrawable(context, R.drawable.ic_bonus)
          menu.add(0, R.id.help, 0, R.string.help).icon = AppCompatResources.getDrawable(context, R.drawable.ic_help)
          menu.add(0, R.id.notifications, 0, R.string.notifications).icon = AppCompatResources.getDrawable(context, R.drawable.ic_notification)
          bind(model.unreadCount) { setBadge(R.id.notifications, if (it &gt; 0) it.toString() else null) }
      }
  
      override fun onDrawerStateChanged(newState: Int) {
  
      }
  
      override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
  
      }
  
      override fun onDrawerClosed(drawerView: View) {
          try {
              childFragmentManager.findFragmentById(R.id.fragment_navigation_main)?.userVisibleHint = false
          } catch (_: IllegalStateException) {
          }
      }
  
      override fun onDrawerOpened(drawerView: View) {
          try {
              childFragmentManager.findFragmentById(R.id.fragment_navigation_main)?.userVisibleHint = true
          } catch (_: java.lang.IllegalStateException) {
          }
      }
  
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
          updateTitle()
      }
  
      private fun updateTitle() {
          when (view?.flipper?.displayedChild) {
              0 -&gt; view?.toolbar?.setTitle(R.string.your_bright_shopping)
              1 -&gt; view?.toolbar?.setTitle(R.string.news)
              2 -&gt; view?.toolbar?.setTitle(R.string.bonus)
              3 -&gt; view?.toolbar?.setTitle(R.string.help)
              4 -&gt; view?.toolbar?.setTitle(R.string.notifications)
          }
      }
  
      @SuppressLint("RestrictedApi")
      private fun notifyFragments() {
          val currentPage = view?.flipper?.displayedChild ?: return
          val shoppingFragment = childFragmentManager.findFragmentById(R.id.shoppingFragment)
          val newsFragment = childFragmentManager.findFragmentById(R.id.newsFragment)
          val bonusFragment = childFragmentManager.findFragmentById(R.id.bonusFragment)
          val notificationsFragment = childFragmentManager.findFragmentById(R.id.notificationsFragment)
          val helpFragment = childFragmentManager.findFragmentById(R.id.helpFragment)
          shoppingFragment?.userVisibleHint = currentPage == 0
          newsFragment?.userVisibleHint = currentPage == 1
          bonusFragment?.userVisibleHint = currentPage == 2
          helpFragment?.userVisibleHint = currentPage == 3
          notificationsFragment?.userVisibleHint = currentPage == 4
          val menu = view?.toolbar?.menu ?: return
          val inflater = SupportMenuInflater(view?.toolbar?.context)
          menu.clear()
          when (currentPage) {
              0 -&gt; shoppingFragment.onCreateOptionsMenu(menu, inflater)
              1 -&gt; newsFragment.onCreateOptionsMenu(menu, inflater)
              2 -&gt; bonusFragment.onCreateOptionsMenu(menu, inflater)
              3 -&gt; helpFragment.onCreateOptionsMenu(menu, inflater)
              4 -&gt; notificationsFragment.onCreateOptionsMenu(menu, inflater)
          }
      }
  
      override fun onSaveInstanceState(outState: Bundle) {
          super.onSaveInstanceState(outState)
          outState.putInt(KEY_CURRENT_ITEM, view?.flipper?.displayedChild ?: 0)
      }
  
      override fun onBackPressed(): Boolean {
          val drawer = view?.drawer ?: return false
          return when {
              drawer.isDrawerOpen(Gravity.START) -&gt; {
                  drawer.closeDrawer(Gravity.START)
                  true
              }
              view?.bottomNavigation?.selectedItemId == R.id.main -&gt; false
              else -&gt; {
                  view?.bottomNavigation?.selectedItemId = R.id.main
                  true
              }
          }
      }
  
       fun onBackPressedNews(): Boolean {
  
                  view?.bottomNavigation?.selectedItemId = R.id.news
  
              return true
  
      }
  
  
      override fun onNavigationItemSelected(item: MenuItem): Boolean {
          val page = when (item.itemId) {
              R.id.main -&gt; 0
              R.id.news -&gt; 1
              R.id.bonus -&gt; 2
              R.id.help -&gt; 3
              R.id.notifications -&gt; 4
              else -&gt; return false
          }
          view?.flipper?.displayedChild = page
          updateTitle()
          notifyFragments()
          return true
      }
  
  
      companion object {
          private const val KEY_CURRENT_ITEM = "current_item"
      }
  
  }
  </code></pre>
  
  <p><code>AlertBoxActivity.kt</code></p>
  
  <p>Activity where I call <code>showNewsPageTime()</code> method, but when running android has stopped.</p>
  
  <pre><code>    package kz.app
  
      import android.support.design.widget.BottomNavigationView
      import android.annotation.SuppressLint
      import android.os.Bundle
      import android.support.v7.app.AppCompatActivity
      import android.support.v4.app.FragmentManager;
      import kotlinx.android.synthetic.main.fragment_main.*
      import kotlinx.android.synthetic.main.fragment_parking_payment.*
      import kotlinx.android.synthetic.main.fragment_shopping.*
      import kz.app.api.entity.PromoAction
      import kz.app.model.PromoActionViewModel
      import kz.app.fragment.NewsFragment
      import kz.app.fragment.PromoDetailsFragment
      import kz.app.fragment.MainFragment
      import kz.app.fragment.ShoppingDetailsFragment
      import kz.app.model.PromoDetailsViewModel
      import android.widget.FrameLayout;
      import android.R
  
      class AlertBoxActivity : AppCompatActivity() {
  
          override fun onCreate(savedInstanceState: Bundle?) {
              val fragmentManager = supportFragmentManager
              super.onCreate(savedInstanceState)
              val obj = MainFragment()
              obj.showNewsPageTime()
              if (savedInstanceState == null) {
  
                  getSupportFragmentManager().beginTransaction()
                          .add(android.R.id.content, obj)
                          .commit()
  </code></pre>