activity管理

 public class MainApp extends Application {

      private static ArrayList<WeakReference<Activity>> activitys;
public volatile static MainApp instance;
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
} public MainApp() {
// TODO Auto-generated constructor stub
}
public static MainApp getInstance(){
if(instance==null){
synchronized (MainApp.class) {
if(instance==null){
instance=new MainApp();
}
}
}
return instance;
} public static void addActivity(Activity context) {
if(activitys==null){
activitys=new ArrayList<WeakReference<Activity>>();
}
activitys.add(new WeakReference<Activity>(context));
} public static void removeActivity(Activity activity) { if(activity!=null){ activitys.remove(new WeakReference<Activity>(activity));
activity.finish();
activity=null;
} } public static void finishAllActivity() {
Activity activity;
for (int i = activitys.size() - 1; i >= 0; i--) {
activity = activitys.get(i).get();
if (activity != null && !activity.isFinishing()) {
activity.finish();
}
}
activitys.clear();
}
上一篇:VC 模拟键盘输入


下一篇:http服务&ajax编程