title: How to use data from onActivityResult in MVVM architecture?
body: <p>How to use data from onActivityResult in MVVM architecture? I need to add an item to the RecyclerView that is subscribed to receive data from the ViewModel. How can I send data from onActivityResult to the ViewModel class and then update my list? If I add data to the adapter immediately from the onactivityresult method, nothing happens. I need any help on this issue</p>
  
  <p>Activity class:</p>
  
  <pre><code>class ContactsActivity : AppCompatActivity(), ContactsListener {
      private val TAG = "ContactsActivity"
  
      @Inject
      lateinit var factory: ViewModelProvider.Factory
      lateinit var contactsViewModel: ContactsViewModel
  
  
      companion object {
          const val ADD_CONTACT_REQUEST = 200
      }
  
      private lateinit var mAdapter: ContactsAdapter
  
      @SuppressLint("WrongConstant")
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
  
          toolbar_contacts.title = getString(R.string.contacts_toolbar_title)
  
          add_new_contact_btn.setOnClickListener {
              val intent = Intent(this@ContactsActivity, AddContactActivity::class.java)
              startActivityForResult(intent, ADD_CONTACT_REQUEST)
          }
  
          DaggerContactsActivity_ContactsComponent.create().inject(this@ContactsActivity)
          contactsViewModel = ViewModelProviders.of(this@ContactsActivity, factory).get(ContactsViewModel::class.java)
          contactsViewModel.getContactsList().observe(this@ContactsActivity, Observer {
  
              mAdapter = ContactsAdapter(this@ContactsActivity, it)
              recycler_contacts.layoutManager =
                  LinearLayoutManager(applicationContext, OrientationHelper.VERTICAL, false)
              recycler_contacts.adapter = mAdapter
              recycler_contacts.setHasFixedSize(true)
  
              mAdapter.sortByName()
  
          })
      }
  
      // Dagger create
      @Component (modules = [ContactsModule::class])
      interface ContactsComponent {
  
          fun inject (activity: ContactsActivity)
      }
  
      @Module
      abstract class ContactsModule {
  
          @Binds
      abstract fun bindViewModelFactory(factory: ContactsViewModelFactory): ViewModelProvider.Factory
      }
  
      override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
          super.onActivityResult(requestCode, resultCode, data)
              if (resultCode == ADD_CONTACT_REQUEST &amp;&amp; resultCode == RESULT_OK) {
                  val firstName: String? = data?.getStringExtra(AddContactActivity.EXTRA_FIRST_NAME)
                  val lastName: String? = data?.getStringExtra(AddContactActivity.EXTRA_LAST_NAME)
                  val phone: String? = data?.getStringExtra(AddContactActivity.EXTRA_PHONE)
                  val email: String? = data?.getStringExtra(AddContactActivity.EXTRA_EMAIL)
                  val notes: String? = data?.getStringExtra(AddContactActivity.EXTRA_NOTES)
  
                  val contacts = Contacts(firstName = firstName.toString(), lastName = lastName.toString(), phone = phone.toString(),
                      email = email.toString(), notes = notes.toString(), images = "")
  
                  contactsViewModel.get(contacts = contacts)
              }
          }
  
      override fun setupContactsList(contactsList: ArrayList&lt;Contacts&gt;) {
  
          mAdapter.setupContacts(contactsList = contactsList)
      }
  }
  </code></pre>