From d50752009d19643da104e67ba32b23ea7ae46461 Mon Sep 17 00:00:00 2001
From: LeeKi <543945827@qq.com>
Date: Tue, 18 Sep 2018 15:08:06 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DActivityUtil=E4=B8=ADIntent?=
=?UTF-8?q?=E8=B7=B3=E8=BD=AC=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
.../java/com/liqi/utils/ActivityUtil.java | 84 +++++++++++++++++++
2 files changed, 85 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 6e760b5..e040632 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ allprojects {
```
**2:依赖MyUtils**
```gradle
-compile 'com.github.liqinew:myutils:V.1.1.3'
+compile 'com.github.liqinew:myutils:V.1.1.4'
```
### [点击查阅MyUtils-API文档](https://liqinew.github.io/MyUtils/)
diff --git a/utils/src/main/java/com/liqi/utils/ActivityUtil.java b/utils/src/main/java/com/liqi/utils/ActivityUtil.java
index 5e229f2..671d89f 100644
--- a/utils/src/main/java/com/liqi/utils/ActivityUtil.java
+++ b/utils/src/main/java/com/liqi/utils/ActivityUtil.java
@@ -75,6 +75,9 @@ public void startActivity(Context context, Class clazz) {
if (null != context && null != clazz) {
clearIntent();
mIntent.setClass(context, clazz);
+ if (!(context instanceof Activity)) {
+ mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ }
context.startActivity(mIntent);
} else {
Logger.e(TAG + "startActivity()", "参数值传入为空");
@@ -139,6 +142,67 @@ public void startActivityClearAllInstances(Context context, Class> clazz) {
// }
// }
+ /**
+ * 获取配置完毕的intent对象
+ *
+ * @param context 上下文
+ * @param clazz 目标activity.class
+ * @param data Object类型的数据
+ * key:名称
+ * value:Object类型值,支持的类型(String,Integer,Boolean,Double,Float,Long,Serializable)
+ */
+ public Intent getConfigurationIntent(Context context, Class clazz, Map data) {
+ if (null != context && null != clazz) {
+ clearIntent();
+ mIntent.setClass(context, clazz);
+ if (data != null) {
+ for (Entry en : data.entrySet()) {
+ Object value = en.getValue();
+ if (value instanceof String) {
+ mIntent.putExtra(en.getKey(), en.getValue().toString());
+ continue;
+ }
+ if (value instanceof Integer) {
+ mIntent.putExtra(en.getKey(), (int) en.getValue());
+ continue;
+ }
+ if (value instanceof Boolean) {
+ mIntent.putExtra(en.getKey(), (boolean) en.getValue());
+ continue;
+ }
+ if (value instanceof Double) {
+ mIntent.putExtra(en.getKey(), (double) en.getValue());
+ continue;
+ }
+ if (value instanceof Float) {
+ mIntent.putExtra(en.getKey(), (float) en.getValue());
+ continue;
+ }
+ if (value instanceof Long) {
+ mIntent.putExtra(en.getKey(), (long) en.getValue());
+ continue;
+ }
+ if (value instanceof Serializable) {
+ mIntent.putExtra(en.getKey(), (Serializable) en.getValue());
+ } else {
+ mIntent.putExtra(en.getKey(), "");
+ Logger.e(TAG + "getConfigurationIntent()", "传入的类型不符合规定>>>>默认传输值:\"\"");
+ }
+
+ }
+ } else {
+ Logger.e(TAG + "getConfigurationIntent()", "参数data的值传入为空");
+ }
+
+ if (!(context instanceof Activity)) {
+ mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ }
+ } else {
+ Logger.e(TAG + "getConfigurationIntent()", "参数值传入为空");
+ }
+ return mIntent;
+ }
+
/**
* 开启一个新的activity
*
@@ -190,6 +254,11 @@ public void startActivityWithObjectData(Context context, Class clazz, Map