Skip to content

Instantly share code, notes, and snippets.

@Sethathi
Created March 23, 2022 07:31
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 Sethathi/df28b8f7887f53ec0953042487d4d71e to your computer and use it in GitHub Desktop.
Save Sethathi/df28b8f7887f53ec0953042487d4d71e to your computer and use it in GitHub Desktop.
// 1. What would happen if a user pressed back button before `fetchProfileDetailsFromServer` completes
// 2. How can we improve this code?
class ProfileActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_profile)
loadProfileDetails()
}
private fun loadProfileDetails() {
GlobalScope.launch(Dispatchers.Main) {
// Let's assume task take 30 seconds to complete
val profile = fetchProfileDetailsFromServer()
updateUi(profile)
Toast.makeText(this@SignInActivity, "Done loading details", Toast.LENGTH_LONG).show()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment