ActivityManager
public class ActivityManager {
private static ActivityManager _instance = new ActivityManager();
private Stack<Activity> activities = new Stack<>();
private static final byte [] writeLock = new byte [0 ];
public Activity getFrontActivity (){
return activities.lastElement();
}
public void addActivity (Activity activity){
if (activity!=null ){activities.add(activity);}
}
public void delActivity (Activity activity){
if (activities.size()>0 ){
if (activities.contains(activity)){
activities.remove(activity);
activity.finish();
}
}
}
public void finishAllActivity (){
while (activities.size()>0 ){
delActivity(getFrontActivity());
}
}
public void backToMain (){
handler.postDelayed(...){
...
while (activities.size()>1 ){
if (!(getFrontActivity() instanceof MainActivity)){delActivity(...)}
else {break ;}
}
}
}
private ActivityManager (){}
public ActivityManager get_instance (){
synchornized(writeLock){
if (_instance == null ){_instance = new ActivityManager(); }
}
}
}