SoFunction
Updated on 2025-04-09

Summary of several ways to exit the Android program


public class ScreenManager {
private static Stack activityStack;
private static ScreenManager instance;
private ScreenManager(){
}
public static ScreenManager getScreenManager(){
instance=new ScreenManager();
}
return instance;
}
//Exit the activity on top of the stack
public void popActivity(Activity activity){
();
(activity);
activity=null;
}
}
//Get the current stack top activity
public Activity currentActivity(){
Activity activity=();
return activity;
}
//Pust the current activity into the stack
public void pushActivity(Activity activity){
activityStack=new Stack();
}
(activity);
}
//Exit all activities in the stack
public void popAllActivityExceptOne(Class cls){
while(true){
Activity activity=currentActivity();
break;
}
break;
}
popActivity(activity);
}
}
}