Learning Mobile Development
A Bug that Wasted Half My Day Debugging in Android Studio!
I never have imagined it’s just such a simple bug actually
Having more than 7 years of experience in Android, makes me feel confident in my knowledge in this area. But today, I feel so embarrassed not able to figure out such a simple issue. I almost wanted to pull my hair out when I discover that.
Let me bring you through the journey, and see if your thought process is the same as mine…
It started with just an Activity
To save some time, I just get on to the most basic form of how I replicate this strange issue.
All I need to do is just create an Empty Activity project and Logcat onCreate
, onStart
, onResume
, onPause
, onStop
, onSaveInstanceState
, and onDestroy
.
A sample just below
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d("Tracking", "onCreate")
setContentView(R.layout.activity_main)
} // Other codes
}
To my surprise, I discovered that one a single launch, multiple instances of…