简体   繁体   中英

Is CountDownTimer cancelled automatically on Activity destroy()?

A question, maybe a little naive...

If I start a 2 minute CountDownTimer in Activity onCreate() and close it with finish() when user clicks a button, does Android cancel it automatically?

Or do I need to explicitly call cancel() in onDestroy()?

You will have to explicitly call cancel in Ondestroy . But better practice is to call cancel in Onpause .
Since if you have paused your activity and you update any Ui elements inside OnFinish of the countdown timer it may throw errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM