当前位置:网站首页>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
边栏推荐
- Eight misunderstandings that should be avoided in data visualization
- 解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].
- QML advanced (V) - realize all kinds of cool special effects through particle simulation system
- Recommended scheme for national production of electronic components for wireless charging
- Unity RawImage背景无缝连接移动
- js 判斷數字字符串中是否含有字符
- Migrate from MySQL database to AWS dynamodb
- What is the meaning of load balancing
- Getprop property
- leetcode001--返回和为target的数组元素的下标
猜你喜欢
520. Detect capital letters
AWS eks add cluster user or Iam role
Mysql50 basic exercises
Druid -- JDBC tool class case
Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
Use model load_ state_ Attributeerror appears when dict(): 'STR' object has no attribute 'copy‘
New terminal play method: script guidance independent of technology stack
Go reflection rule
C language: Advanced pointer
redis数据类型有哪些
随机推荐
IDE idea automatic compilation and configuration of on update action and on frame deactivation
Teach you how to build the ruoyi system by Tencent cloud
520. Detect capital letters
Simply drag objects to the item bar
Unity RawImage背景无缝连接移动
A heavy sword without a blade is a great skill
List remove an element
Customize the navigation bar at the top of wechat applet (adaptive wechat capsule button, flex layout)
QML advanced (IV) - drawing custom controls
Custom switch control
Windows remote connection to redis
The last day of 2021 is the year of harvest.
ApplicationContext injection bean
Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
Spark FAQ sorting - must see before interview
The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
Flink's important basics
leetcode004--罗马数字转整数
Recursive call -- Enumeration of permutations
Jetpack -- lifecycle usage and source code analysis