当前位置:网站首页>从零开始学安卓(kotlin)三——BaseActivity、ActivityCollector
从零开始学安卓(kotlin)三——BaseActivity、ActivityCollector
2022-04-22 05:56:00 【散月】
BaseActivity
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
open class BaseActivity:AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d("BaseActivity", javaClass.simpleName)
ActivityCollector.addActivity(this)
}
override fun onDestroy() {
super.onDestroy()
ActivityCollector.removeActivity(this)
}
}
ActivityCollector——随时随地退出程序
import android.app.Activity
object ActivityCollector {
private val activities = ArrayList<Activity>()
fun addActivity(activity: Activity) {
activities.add(activity)
}
fun removeActivity(activity: Activity) {
activities.remove(activity)
}
fun finishAll() {
for (activity in activities) {
if (!activity.isFinishing) {
activity.finish()
} }
activities.clear()
android.os.Process.killProcess(android.os.Process.myPid())
}
}
版权声明
本文为[散月]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_43480289/article/details/124305363
边栏推荐
猜你喜欢

PostgreSQL中的MVCC 事务隔离

The annual list of its intelligent service excellent enterprises was released, and Kyushu cloud won the "2021 top 10 of Xinchuang operation and maintenance"

PostgreSQL中Oid和Relfilenode的映射

mysql知识点总结

uglifyjs压缩JS

Pgdoucer best practices: Series 4

数美科技入选2021朝阳高科技高成长20强

Solve the problem of error in installing PostgreSQL under windows2012 R2

Kyushu cloud passes the authoritative evaluation of EC ready edge cloud

Iframe子父级传参
随机推荐
解决Windows2012 R2下安装PostgreSQL报错的问题
Using pgbackrest parallel archiving to solve wal stacking problem
Summary of redis core knowledge points (super detailed)
为PostgreSQL的表自动添加分区
Good news | Kyushu cloud was rated as "Zhejiang high tech enterprise research and development center"
Topic of SSM source code
《信息系统项目管理师总结》第三章 项目进度管理
区间列表的交集
使用AES加密-复用前人的智慧
Functions and differences between call and apply
企业风控如何搭建四大体系,实现全局防控?
《通用数据保护条例》(GDPR)系列解读一:如何判断出海企业是否受GDPR管辖?
MYSQL 查看优化器后执行得SQL语句详情
数美科技荣登界面新闻 “REAL 100创新家”新企服赛道TOP20
Pgdoucer best practices: a series
一个三目表达式,引起的空指针
PostgreSQL 13.3, 12.7, 11.12, 10.17 and 9.6.22 have been released!
Openinfra live | Kyushu yunhuang Shuquan was elected track chair and brought wonderful theme sharing
MYSQL聚簇索引
PostgreSQL使用clickhousedb_fdw访问ClickHouse