package com.duoku.cocosx.demo;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.Application;
import android.content.Context;

import com.duoku.platform.single.DKPlatform;
import com.duoku.platform.single.service.DKCrashHandler;


public class DemoApplication extends Application {
	
	private static DemoApplication app;
	
	private List<Activity> activities;
	
	public static DemoApplication getInstance() {
		return app;
	}
	
	private Activity mainActivity;
	
	public Activity getMainActivity() {
		return mainActivity;
	}

	public void setMainActivity(Activity mainActivity) {
		this.mainActivity = mainActivity;
	}

	@Override
    protected void attachBaseContext(Context ctx){
        super.attachBaseContext(ctx);
       
        DKPlatform.getInstance().invokeMMHelperInstall(this);
    }
    
    @Override
	public void onCreate() {
		super.onCreate();

//		DKCrashHandler.getInstance().init(this);
		activities = new ArrayList<Activity>();
		
		try {
			//baidu pass
			DKPlatform.getInstance().invokeBDInitApplication(this);
		} catch (Exception e) {
			// TODO: handle exception
		}

        //移动基地so文件加载
		DKPlatform.getInstance().invokeGBInit(this);
		
		app = this;
	}

	public void in(Activity activity) {
		if (!activities.contains(activity)) {
			activities.add(activity);
		}
	}
	
	public void finishAll() {
		for (Activity activity : activities) {
			activity.finish();
		}
	}
}
