Skip to content

Instantly share code, notes, and snippets.

@malwinder-s
Last active April 4, 2018 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malwinder-s/a131b45d5ce90d6345349c8cd5e75f7a to your computer and use it in GitHub Desktop.
Save malwinder-s/a131b45d5ce90d6345349c8cd5e75f7a to your computer and use it in GitHub Desktop.
Example of code with boilerplate removed
private fun launchStudentDetailsActivity(id: String, name: String, totalScore: Int) {
val intent = Intent(this, StudentDetailsActivity::class.java)
intent.replaceExtras(getExtras(id, name, totalScore))
startActivity(intent)
}
private fun launchStudentEditorActivity(id: String, name: String, totalScore: Int) {
val intent = Intent(this, StudentEditorActivity::class.java)
intent.replaceExtras(getExtras(id, name, totalScore))
startActivity(intent)
}
private fun getExtras(id: String, name: String, totalScore: Int): Bundle {
val extras = Bundle()
extras.putString(EXTRA_STUDENT_ID, id)
extras.putString(EXTRA_STUDENT_NAME, name)
//Suppose "totalScore" is score of student in 5 subjects.
val totalPercentage = totalScore / 5
extras.putString(EXTRA_STUDENT_PERCENTAGE, totalPercentage)
return extras
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment