Skip to content

Instantly share code, notes, and snippets.

@WrathChaos
Last active February 10, 2020 09:24
Show Gist options
  • Save WrathChaos/cea0343ba9579c00ecf384d8c89e15ca to your computer and use it in GitHub Desktop.
Save WrathChaos/cea0343ba9579c00ecf384d8c89e15ca to your computer and use it in GitHub Desktop.
class MyFragment: Fragment() {
  private lateinit var myObject: MyObject
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      if (arguments != null) {
          myObject = arguments!!.getParcelable(ARG_PARAM)
      }
  }
  
  companion object {
      private val ARG_PARAM = "myObject"
  
      /**
       * Use this factory method to create a new instance of
       * this fragment using the provided parameters.
       *
       * @param myObject as MyObject.
       * @return A new instance of fragment MyFragment.
       */
      fun newInstance(myObject: MyObject): MyFragment {
          val fragment = MyFragment()
          val args = Bundle()
          args.putParcelable(ARG_PARAM, myObject)
          fragment.arguments = args
          return fragment
      }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment