前言:
各位同学大家好 今天在加班 因为想第二天晚点到 无奈哈 所有加班到11点半 想着加班就没学点啥技术 就去看了下LifeCycle 这个想法很多网友都出过文章 我这边就只是做个记录哈
效果图
我们现在有这样一个需求 就是计时器的 如图上所示 我们在activity 启动的时候 进去 onResume 生命周期方法 启动 然后在应用去到后台 进入 onPause 暂停
传统写法
布局文件 这边用到是的 Chronometer 控件实现
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.example.lifecycledemo.MyChronometer
android:id&#