当前位置:网站首页>Singleton mode encapsulates activity management class
Singleton mode encapsulates activity management class
2022-07-05 10:16:00 【asahi_ xin】
public class AppManager {
private Stack<Activity> activityStack;
private AppManager() {
activityStack = new Stack<>();
}
public static AppManager getInstance() {
return AppHolder.appManager;
}
private static class AppHolder {
private static AppManager appManager = new AppManager();
}
/** * add to activity * * @param activity activity */
public void addActivity(Activity activity) {
activityStack.add(activity);
}
/** * remove activity * * @param activity activity */
public void removeActivity(Activity activity) {
activityStack.remove(activity);
}
/** * Get current Activity */
private Activity currentActivity() {
return activityStack.lastElement();
}
/** * Remove and close activity * * @param activity activity */
public void finishActivity(Activity activity) {
removeActivity(activity);
activity.finish();
}
/** * Remove and close all activity */
public void finishAllActivity() {
for (Activity activity : activityStack) {
if (null != activity) {
activity.finish();
}
}
activityStack.clear();
}
/** * sign out app Called when the */
public void exitApp() {
try {
finishAllActivity();
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
}
边栏推荐
- 《剑来》语句摘录(七)
- 历史上的今天:第一本电子书问世;磁条卡的发明者出生;掌上电脑先驱诞生...
- To bring Euler's innovation to the world, SUSE should be the guide
- Cent7 Oracle database installation error
- 天龙八部TLBB系列 - 单体技能群伤
- Events and bubbles in the applet of "wechat applet - Basics"
- Coffeescript Chinese character to pinyin code
- QT timer realizes dynamic display of pictures
- Swift uses userdefaults and codable to save an array of class objects or structure instances
- Generics, generic defects and application scenarios that 90% of people don't understand
猜你喜欢
QT realizes signal transmission and reception between two windows
What is the origin of the domain knowledge network that drives the new idea of manufacturing industry upgrading?
程序员如何活成自己喜欢的模样?
Getting started with Apache dolphin scheduler (one article is enough)
Kotlin compose multiple item scrolling
AtCoder Beginner Contest 258「ABCDEFG」
如何写出高质量的代码?
Meitu lost 300 million yuan in currency speculation for half a year. Huawei was exposed to expand its enrollment in Russia. Alphago's peers have made another breakthrough in chess. Today, more big new
[论文阅读] KGAT: Knowledge Graph Attention Network for Recommendation
Kotlin Compose 与原生 嵌套使用
随机推荐
Wechat applet - simple diet recommendation (4)
一种用于干式脑电图的高密度256通道电极帽
面试:Bitmap像素内存分配在堆内存还是在native中
Livedata interview question bank and answers -- 7 consecutive questions in livedata interview~
@Jsonadapter annotation usage
MySQL字符类型学习笔记
Hard core, have you ever seen robots play "escape from the secret room"? (code attached)
小程序中自定义行内左滑按钮,类似于qq和wx消息界面那种
Z-blog template installation and use tutorial
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条...
Detailed explanation of the use of staticlayout
mongoDB副本集
[system design] index monitoring and alarm system
伪类元素--before和after
Windows uses commands to run kotlin
Interview: is bitmap pixel memory allocated in heap memory or native
《微信小程序-基础篇》小程序中的事件与冒泡
AtCoder Beginner Contest 258「ABCDEFG」
Swift saves an array of class objects with userdefaults and nssecurecoding
The horizontally scrolling recycleview displays five and a half on one screen, lower than the average distribution of five