private static Stack<Activity> activityStack;
文_ 2017/7/29 14:45:18
/** * 添加Activity到堆栈 */
public void addActivity(Activity activity) {
if (activityStack == null) {
activityStack = new Stack<Activity>();
}
activityStack.add(activity);
}
/** * 结束指定类名的Activity */
public void finishActivity(Class<?> cls) {
for (Activity activity : activityStack) {
if (activity.getClass().equals(cls)) {
finishActivity(activity);
}
}
}
/** * 结束所有Activity */
public void finishAllActivity() {
for (int i = 0, size = activityStack.size(); i < size; i++) {
if (null != activityStack.get(i)) {
activityStack.get(i).finish();
}
}
activityStack.clear();
} /** * 获取当前Activity(堆栈中最后一个压入的) */
public Activity currentActivity() {
Activity activity = activityStack.lastElement();
return activity;
}
/** * 结束当前Activity(堆栈中最后一个压入的) */
public void finishActivity() {
Activity activity = activityStack.lastElement();
if (activity != null) {
activity.finish();
activity = null;
}
}
退出多个activity
最新推荐文章于 2021-05-26 18:40:37 发布