当前位置:网站首页>Learning Android from scratch -- baseactivity and activitycollector
Learning Android from scratch -- baseactivity and activitycollector
2022-04-23 04:47:00 【Scattered moon】
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—— Exit the program anytime, anywhere
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())
}
}
版权声明
本文为[Scattered moon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220555418213.html
边栏推荐
- unity摄像机旋转带有滑动效果(自转)
- IDE idea automatic compilation and configuration of on update action and on frame deactivation
- Practice and exploration of knowledge map visualization technology in meituan
- List remove an element
- Perfect test of coil in wireless charging system with LCR meter
- KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘
- JS generates a specified number of characters according to some words
- Spark optimization
- Improving 3D object detection with channel wise transformer
- POI export message list (including pictures)
猜你喜欢
做数据可视化应该避免的8个误区
Excel uses the functions of replacement, sorting and filling to comprehensively sort out financial data
[paper reading] [3D target detection] point transformer
Record your own dataset with d435i, run orbslam2 and build a dense point cloud
Go reflection rule
Spark FAQ sorting - must see before interview
Arduino UNO r3+LCD1602+DHT11
PHP+MySQL 制作留言板
PIP3 installation requests Library - the most complete pit sorting
Teach you how to build the ruoyi system by Tencent cloud
随机推荐
QML进阶(四)-绘制自定义控件
Innovation training (V) mid term inspection
Getprop property
getprop 属性
The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
What is the thirty-six plan
js 判断数字字符串中是否含有字符
What is a blocking queue? What is the implementation principle of blocking queue? How to use blocking queue to implement producer consumer model?
redis和mysql区别
The programmer starts the required application with one click of window bat
简单的拖拽物体到物品栏
AWS eks add cluster user or Iam role
Spark small case - RDD, spark SQL
leetcode001--返回和为target的数组元素的下标
Opencv + clion face recognition + face model training
520. Detect capital letters
Unity攝像頭跟隨鼠標旋轉
Unity3d practical skills - theoretical knowledge base (I)
Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
Small volume Schottky diode compatible with nsr20f30nxt5g