Created
June 10, 2019 23:20
-
-
Save ivanalvarado/df8094e86e8562925ff9b69d9bbaf92e to your computer and use it in GitHub Desktop.
Activity that passes argument to ViewModel via public setter method instead of Constructor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const val ARGUMENT_USER_ID = "ARGUMENT_USER_ID" | |
class UserDetailActivity : AppCompatActivity() { | |
@Inject | |
internal lateinit var viewModelFactory: ViewModelProvider.Factory | |
private lateinit var userDetailViewModel: UserDetailViewModel | |
override fun onCreate(savedInstanceState: Bundle?) { | |
// ... | |
userDetailViewModel = ViewModelProviders.of(this, viewModelFactory).get(UserDetailViewModel::class.java) | |
userDetailViewModel.setUserDetail(intent.getStringExtra(ARGUMENT_USER_ID)) | |
userDetailViewModel.getUserDetail().observe(this, Observer<UserDetailModel>{ userDetail -> | |
// update UI | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment