Skip to content

Instantly share code, notes, and snippets.

View Sethathi's full-sized avatar
🏗️

Sethathi Morokole Sethathi

🏗️
View GitHub Profile
// 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()
}
# Which dispatcher should be used for which use case?
## Dispatchers
a) Dispatchers.Main
b) Dispatchers.IO
c) Dispatchers.Default
// `BookingsActivity` is rotatable and currently loads bookings from API on each rotation. How can we prevent this from happening?
class BookingViewModel(
private val repository: BookingsRepository
) : ViewModel() {
// We want to make sure that this is only settable privately.
val bookings = MutableLiveData<List<Booking>>()
fun loadBookings() {
val bookings = repository.getBookings()
// Can you spot any issues with code?
class MyBroadcastReceiverActivity : AppCompatActivity() {
private var broadcastReceiver: BroadcastReceiver? = null
override fun onCreate(@Nullable savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_one)
}
private fun registerBroadCastReceiver() {
broadcastReceiver = object : BroadcastReceiver() {