I'm a beginner in android.
And I'm making an application about health care.
What I want to ask is how to finish an activity in the beneath case. The problem is the activity is not finished when I push the 'Back button' and 'ImageButton29'. To be specific, the countdowntimer still operates after I push those buttons... So, even if I go to next or previous pages(activity), after the countdown, the 'pushtaba2' activity is implemented. Please answer me.
package com.example.myapp
import android.os.Bundle
import android.os.CountDownTimer
import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_pushtaba1.*
import android.content.Intent as Intent
class pushtaba1 : AppCompatActivity() {
override fun onBackPressed() {
finish()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_pushtaba1)
val intent = Intent(this, pushtaba2::class.java)
val value = object : CountDownTimer(10000, 1000) {
override fun onTick(millisUntilFinished: Long) {
mTextField3.setText("" + millisUntilFinished / 1000)
}
override fun onFinish() {
startActivity(intent)
finish()
}
}.start()
imageButton29.setOnClickListener {
startActivity(intent)
finish()
}
}
}
Override the fun
onDestroy()inAppCompatActivity. This will be called whenever the Activity gets destroyed.