package com.lee.base.activity;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.FragmentActivity;

import java.util.List;

/**
 * FragmentActivity Base
 * </p>
 * Created by LiYang on 2017/1/3.
 */

public class BaseFragmentActivity extends FragmentActivity{

    // TODO: 2017/1/3 common deal

    public void startActivity(Intent intent) {
        if(this.isIntentAvailable(intent)) {
            super.startActivity(intent);
        }
    }

    public void startActivityForResult(Intent intent, int requestCode) {
        if(this.isIntentAvailable(intent)) {
            super.startActivityForResult(intent, requestCode);
        }
    }

    /**
     * Check the Intent validity
     */
    private boolean isIntentAvailable(Intent intent) {
        if(intent == null) {
            return false;
        } else {
            PackageManager packageManager = this.getPackageManager();
            List list = packageManager.queryIntentActivities(intent, 1);
            return list.size() > 0;
        }
    }

}
