intent的整合工具

public class StartIntent {

	private static StartIntent startIntent = null;

	public static StartIntent getStartIntet() {
		if (startIntent == null) {
			startIntent = new StartIntent();
		}
		return startIntent;
	}

	/**
	 * 不带参数的回调
	 * 
	 * @Title: setFinishSetReuslt
	 * @param @param act
	 * @param @param requestCode
	 * @return void
	 * @throws
	 */
	public void setFinishSetReuslt(Activity act, int requestCode) {
		act.setResult(requestCode);
	}

	/**
	 * 带有Map<String,String>的参数回调
	 * 
	 * @Title: setFinishMapSetReuslt
	 * @param @param act
	 * @param @param requesCode
	 * @param @param map
	 * @return void
	 * @throws
	 */
	public void setFinishMapSetReuslt(Activity act, int requesCode,
			Map<String, String> map) {
		Intent intent = new Intent();
		intent.putExtra("map", (Serializable) map);
		act.setResult(requesCode, intent);
	}

	/**
	 * 带有Map<String,Object>的参数回调
	 * 
	 * @Title: setFinshMapObjectSetReuslt
	 * @param @param act
	 * @param @param requesCode
	 * @param @param map
	 * @return void
	 * @throws
	 */
	public void setFinshMapObjectSetReuslt(Activity act, int requesCode,
			Map<String, Object> map) {
		Intent intent = new Intent();
		intent.putExtra("map", (Serializable) map);
		act.setResult(requesCode, intent);
	}

	/**
	 * 带有Map<String,Object>的参数回调
	 * 
	 * @Title: setFinshMapObjectSetReuslt
	 * @param @param act
	 * @param @param requesCode
	 * @param @param map
	 * @return void
	 * @throws
	 */
	public void setFinshStrSetReuslt(Activity act, int requesCode,
			Map<String, Object> map) {
		Intent intent = new Intent();
		intetnPut(map, intent);
		act.setResult(requesCode, intent);
	}

	/*----------------------------------setActivityResult----------------*/
	/**
	 * 不带参数的ActivityResult
	 * 
	 * @Title: setActivityResult
	 * @param @param act
	 * @param @param cls
	 * @param @param requestCode
	 * @return void
	 * @throws
	 */
	public void setActivityResult(Activity act, Class<?> cls, int requestCode) {
		Intent intent = new Intent(act, cls);
		act.startActivityForResult(intent, requestCode);
	}

	/**
	 * 带Map<String,String>的参数ActivityResult
	 * 
	 * @Title: setMapActivityResult
	 * @param @param map
	 * @param @param act
	 * @param @param cls
	 * @param @param requestCode
	 * @return void
	 * @throws
	 */
	public void setMapActivityResult(Map<String, String> map, Activity act,
			Class<?> cls, int requestCode) {
		Intent intent = new Intent(act, cls);
		intent.putExtra("map", (Serializable) map);
		act.startActivityForResult(intent, requestCode);
	}

	/**
	 * 帶Map<String,Object>的參數ActivityResult
	 * 
	 * @Title: setMapObjectActivityResult
	 * @param @param map
	 * @param @param act
	 * @param @param cls
	 * @param @param requestCode
	 * @return void
	 * @throws
	 */
	public void setMapObjectActivityResult(Map<String, Object> map,
			Activity act, Class<?> cls, int requestCode) {
		Intent intent = new Intent(act, cls);
		intent.putExtra("map", (Serializable) map);
		act.startActivityForResult(intent, requestCode);
	}

	/**
	 * 带参数的ActivityResult
	 * 
	 * @Title: setStringActivityResult
	 * @param @param map
	 * @param @param act
	 * @param @param cls
	 * @param @param requestCode
	 * @return void
	 * @throws
	 */
	public void setStringActivityResult(Map<String, Object> map, Activity act,
			Class<?> cls, int requestCode) {
		Intent intent = new Intent(act, cls);
		intetnPut(map, intent);
		act.startActivityForResult(intent, requestCode);
	}

	/**
	 * 直接跳转不带任何参数
	 * 
	 * @Title: setIntent
	 * @param @param context
	 * @param @param cls
	 * @return void
	 * @throws
	 */
	public void setIntent(Context context, Class<?> cls) {
		Intent intent = new Intent(context, cls);
		context.startActivity(intent);
	}

	/**
	 * intent通过action的方式跳转到下一个 activity
	 * 
	 * @Title: setIntentAction
	 * @param @param context
	 * @param @param action
	 * @return void
	 * @throws
	 */
	public void setIntentAction(Context context, String action) {
		Intent intent = new Intent(action);
		context.startActivity(intent);
	}

	/**
	 * 
	 * @Title: setIntentStrAction
	 * @param @param context
	 * @param @param putStr
	 * @param @param cls
	 * @return void
	 * @throws
	 */
	public void setIntentStrAction(Context context, Class<?> cls, String putStr) {
		Intent intent = new Intent(context, cls);
		intent.putExtra("strType", putStr);
		context.startActivity(intent);
	}

	/**
	 * 把需要向下传递数据封装到map中,在下一个activity以getIntent.getXXXXX("xxx")的方式获取
	 * 
	 * @Title: startPutActivity
	 * @param @param cls
	 * @param @param map
	 * @return void
	 * @throws
	 */
	public void startIntentPutActivity(Context context, Class<?> cls,
			Map<String, Object> map) {
		if (map != null && !map.isEmpty()) {
			Intent intent = new Intent(context, cls);
			intetnPut(map, intent);
			context.startActivity(intent);
		}
	}

	/**
	 * 封装下一个界面数据
	 * 
	 * @Title: intetnPut
	 * @param @param map
	 * @param @param intent
	 * @return void
	 * @throws
	 */
	private void intetnPut(Map<String, Object> map, Intent intent) {
		Set<String> set = map.keySet();
		Iterator<String> iter = set.iterator();
		while (iter.hasNext()) {// 把map中的数据put到extra里面
			String key = iter.next();
			Object value = map.get(key);
			if (value instanceof String) {
				intent.putExtra(key, (String) value);
			} else if (value instanceof Long) {
				intent.putExtra(key, (Long) value);
			} else if (value instanceof Integer) {
				intent.putExtra(key, (Integer) value);
			} else if (value instanceof Float) {
				intent.putExtra(key, (Float) value);
			} else if (value instanceof Double) {
				intent.putExtra(key, (Double) value);
			} else if (value instanceof Boolean) {
				intent.putExtra(key, (Boolean) value);
			} else if (value instanceof Boolean) {
				intent.putExtra(key, (Boolean) value);
			}
		}
	}

	/**
	 * 直接把map数据put过去
	 * 
	 * @Title: setIntentMap
	 * @param @param context
	 * @param @param cls
	 * @param @param map
	 * @return void
	 * @throws
	 */
	public void setIntentMap(Context context, Class<?> cls,
			Map<String, String> map) {
		if (map != null && !map.isEmpty()) {
			Intent intent = new Intent(context, cls);
			intent.putExtra("map", (Serializable) map);
			context.startActivity(intent);
		}
	}

	/**
	 * 带有标签的传值
	 * 
	 * @Title: setIntentMap
	 * @param @param context
	 * @param @param cls
	 * @param @param map
	 * @param @param falg
	 * @return void
	 * @throws
	 */
	public void setIntentMap(Context context, Class<?> cls,
			Map<String, String> map, boolean falg, String typeActivity) {
		if (map != null && !map.isEmpty()) {
			Intent intent = new Intent(context, cls);
			intent.putExtra("map", (Serializable) map);
			intent.putExtra("booleanFlag", falg);
			intent.putExtra("typeActivity", typeActivity);
			context.startActivity(intent);
		}
	}

	/**
	 * 传递jsonobject数据
	 * 
	 * @Title: setIntentJSONObject
	 * @param @param context
	 * @param @param cls
	 * @param @param jsonObjet
	 * @return void
	 * @throws
	 */
	public void setIntentJSONObject(Context context, Class<?> cls,
			JSONObject jsonObjet) {
		if (jsonObjet != null) {
			Intent intent = new Intent(context, cls);
			intent.putExtra("jsonobject", jsonObjet.toString());
			context.startActivity(intent);
		}
	}

	/**
	 * 直接把map数据put过去
	 * 
	 * @Title: setIntentMap
	 * @param @param context
	 * @param @param cls
	 * @param @param map
	 * @return void
	 * @throws
	 */
	public void setIntentObjectMap(Context context, Class<?> cls,
			Map<String, Object> map) {
		if (map != null && !map.isEmpty()) {
			Intent intent = new Intent(context, cls);
			intent.putExtra("map", (Serializable) map);
			context.startActivity(intent);
		}
	}

	/**
	 * 当你启动多个activity A,B,C和D, 在D Activity里,想再启动一个Activity B,但不变成A,B,C,D,B,
	 * 而是希望是A,B,而且B上的数据依然保留
	 * 
	 * @Title: setSingleActivty
	 * @param @param context
	 * @param @param cls
	 * @return void
	 * @throws
	 */
	public void setSingleActivty(Context context, Class<?> cls) {
		Intent intent = new Intent();
		intent.setClass(context, cls);
		intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);// 设置不要刷新将要跳到的界面
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);// 它可以关掉所要到的界面中间的activity
		context.startActivity(intent);
	}

	/**
	 * 如果已经启动了四个Activity:A,B,C和D,在D Activity里,想再启动一个Activity
	 * B,但不变成A,B,C,D,B,而是希望是A,B,而且B上的数据不保留
	 * 
	 * @Title: setClear
	 * @param @param context
	 * @param @param cls
	 * @return void
	 * @throws
	 */
	public void setClear(Context context, Class<?> cls) {
		Intent intent = new Intent();
		intent.setClass(context, cls);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);// 它可以关掉所要到的界面中间的activity
		context.startActivity(intent);
	}

	/**
	 * 打开推送界面
	 * 
	 * @Title: setIntentNew
	 * @param @param context
	 * @param @param cls
	 * @return void
	 * @throws
	 */
	public void setIntentNew(Context context, Class<?> cls) {
		Intent imap = new Intent(context, cls);
		imap.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(imap);
	}

	/**
	 * 拨打电话
	 * @param context
	 * @param number
	 */
	public void setIntentPhone(Context context, String number) {
		Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
				+ number));
		context.startActivity(intent);
	}

}
只是做一些整理,方便后面来使用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

loves235

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值