I have a query in Kotlin in which a CountDownTimer is running and and the activity goes to a pause state. When it goes to the pause state I'm storing the remaining time of the CountDownTimer in onSaveInstanceState and the timer is stopped using cancel(). Now I want to resume the counter when the activity resumes. But how do I access savedInstanceState inside onResume for knowing the remaining time?
I tried saving the values to a private bundle,
private var bundle:Bundle?=null
.
.
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
bundle?.putInt("time_left",remaining_time)
}
override fun onResume() {
super.onResume()
time = bundle!!.getInt("time_left");
}
.
.
I could have written it in onCreate or using onRestoreInstanceState, but if an activity doesn't go to the onCreate state from onPause state, and directly goes to the onResume state(like when a phone call comes) both onCreate and onRestoreInstanceState will not help. Then how can I update it through onResume?