Created
March 23, 2022 07:31
-
-
Save Sethathi/df28b8f7887f53ec0953042487d4d71e to your computer and use it in GitHub Desktop.
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
// 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