Learning Android Development

7 Android Lifecycle Interview Questions That Some Got Wrong

Getting the Right Lifecycle Understanding is Most Important in Android Development

Photo by Jeremy Bishop on Unsplash

To master Android Development, it is most important one should fully master its lifecycle.

Unfortunately, I came to notice some new Android developers might have accidentally missed out on fully grasping them. It may lead to strange bugs and issue that is hard to debug in the future.

Sharing this, not so much to pass interviews, but also to have a more solid understanding of Android development, preventing pitfalls that can be easily missed.

1. Launch Fragment by Default

Question:

What’s wrong with the code below?

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

supportFragmentManager
.beginTransaction()
.replace(R.id.container, MainFragment())
.commit()
}
}

Wrong Answers:

  1. It didn’t use the KTX to commit the fragment.

--

--