title: How to pass an object from a fragment to an activity detail view using ViewModel(MVVM)?
body: <p>I'm using MVVM as architecture, how can I pass an object from a fragment(recycler + viewModel) to an activity(detail view + viewModel)?</p>
  
  <p>This is the viewmodel for the fragment</p>
  
  <pre><code>class BuyViewModel : ViewModel() {
  private lateinit var buys: MutableLiveData&lt;List&lt;Buy&gt;&gt;
  private var buyRemote = BuyRemote()
  private var buyRepository: BuyRepository = BuyRepository.getInstance(buyRemote)
  
  fun getBuys(): LiveData&lt;List&lt;Buy&gt;&gt; {
      if(!::buys.isInitialized) {
          buys = MutableLiveData()
          buys = buyRepository.getBuys()
      }
      return buys
  }
  
  }
  </code></pre>
  
  <p>This is the Adapter for the fragment</p>
  
  <pre><code>class BuyAdapter(internal var context: Context,
               private var resource: Int,
               private var buyList: ArrayList&lt;Buy&gt;
  ) : RecyclerView.Adapter&lt;BuyAdapter.ViewHolder&gt;() {
  
  override fun getItemCount(): Int {
      return buyList.size
  }
  
  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
      val view = LayoutInflater.from(context)
          .inflate(resource, parent, false)
      return ViewHolder(view)
  }
  
  
  override fun onBindViewHolder(holder: ViewHolder, position: Int) {
      val buy: Buy = buyList[position]
      val propertyImages: List&lt;String&gt; =
          buy.propertyImage.split(",")
  
  
      //Start DetailView Activity
      holder.itemView.setOnClickListener {
          Toast.makeText(context, "clicked", Toast.LENGTH_SHORT).show()
          val intent = Intent(context, BuyDetailActivity::class.java)
          intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
          context.startActivity(intent)
      }
  }
  </code></pre>
  
  <p><code>+++++++++++++++code removed for brevity+++++++++++++++++</code></p>
  
  <p>And finally this is the fragment</p>
  
  <pre><code>class BuyFragment : Fragment() {
  companion object {
      fun newInstance() = BuyFragment()
  }
  
  private lateinit var viewModel: BuyViewModel
  private val buyList = ArrayList&lt;Buy&gt;()
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      viewModel = ViewModelProviders.of(this).get(BuyViewModel::class.java)
  
      viewModel.getBuys().observe(this, Observer&lt;List&lt;Buy&gt;&gt; { buys -&gt;
          buyList.addAll(buys)
          (rvBuy.adapter as BuyAdapter).notifyDataSetChanged()
      })
  }
  
  override fun onCreateView(
      inflater: LayoutInflater, container: ViewGroup?,
      savedInstanceState: Bundle?
  ): View? {
      return inflater.inflate(R.layout.buy_fragment, container, false)
  }
  
  override fun onActivityCreated(savedInstanceState: Bundle?) {
      super.onActivityCreated(savedInstanceState)
      rvBuy.layoutManager = LinearLayoutManager(context)
      rvBuy.adapter = BuyAdapter(activity!!.applicationContext,
          R.layout.buy_card, buyList)
  }
  </code></pre>
  
  <p>How can I implement this while respecting best practices. 
  When the user click an item form the recycler view(fragment) it will pass an object "Buy" to an activity.
  Should that activity uses a view model on its own? How?
  Should the activity use the same viewmodel as the fragment recycler view?</p>