处理多个Activity



public class LifecycleManager {
private static Stack<Activity> activityStack;

private static LifecycleManager instance;

private LifecycleManager() {
}

public static LifecycleManager getLifecycleManager() {
if (instance == null) {
instance = new LifecycleManager();
}
return instance;
}
public void popActivity() {
Activity activity = activityStack.lastElement();
if (activity != null) {
activity.finish();
activityStack.remove(activity);
activity = null;
}
}
public void pushActivity(Activity activity){
if (activityStack == null) {
activityStack  = new Stack<Activity>();
}
activityStack.add(activity);
}
public void popActivity(Activity activity){
if(activity!=null){
activity.finish();
activityStack.remove(activity);
activity=null;
}
}
public Activity currentActivity(){
if(activityStack.size() == 0){
return null;
}
Activity activity = activityStack.lastElement();
return activity;
}
public void popAllActivityExceptOne(Class<?> cls){
while(true){
Activity activity = currentActivity();
if(activity==null){
break;
}
if(activity.getClass().equals(cls) ){
break;
}
popActivity(activity);
}
}
public void exitApp(){
while(true){
Activity activity = currentActivity();
if(activity==null){
break;
}
popActivity(activity);
}
}
}

你可能感兴趣的:(Activity)