浏览代码

[feat]键盘插件,修改跳转方式

hezihao 6 月之前
父节点
当前提交
10ee88f975

+ 4 - 0
android/app/src/main/AndroidManifest.xml

@@ -35,6 +35,10 @@
         <meta-data
             android:name="io.flutter.embedding.android.EnableImpeller"
             android:value="false" />
+        <!-- 禁用3.29版本的线程合并 -->
+        <meta-data
+            android:name="io.flutter.embedding.android.DisableMergedPlatformUIThread"
+            android:value="true" />
         <meta-data
             android:name="UMENG_APPKEY"
             android:value="680dcdadbc47b67d834e37bb" />

+ 11 - 0
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/ActivityUtil.kt

@@ -1,5 +1,6 @@
 package com.atmob.keyboard_android.util
 
+import android.app.Activity
 import android.app.ActivityManager
 import android.content.Context
 import android.content.Context.ACTIVITY_SERVICE
@@ -19,5 +20,15 @@ class ActivityUtil private constructor() {
                 taskList.first().moveToFront()
             }
         }
+
+        /**
+         * Activity是否已经销毁
+         */
+        fun isDestroy(activity: Activity?): Boolean {
+            if (activity == null) {
+                return true
+            }
+            return activity.isDestroyed || activity.isFinishing
+        }
     }
 }

+ 24 - 15
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/FlutterPageLaunchUtil.kt

@@ -42,25 +42,34 @@ class FlutterPageLaunchUtil private constructor() {
             args: Map<String, Serializable?> = mapOf<String, Serializable>(),
             offAll: Boolean = false
         ) {
-            val context = ContextUtil.getContext()
-            val flutterEngine = FlutterEngineHolder.getFlutterEngine()
+//            val context = ContextUtil.getContext()
+//            val flutterEngine = FlutterEngineHolder.getFlutterEngine()
 
             // 构建参数
             val params = buildParams(path, args, offAll)
 
             // 如果Activity存在,直接通过MethodChannel跳转Flutter页面
             val currentActivity = ActivityProvider.get().currentActivity
-            if (currentActivity != null && flutterEngine != null) {
-                // 如果App在后台,则将App移动到前台
-                if (AppMonitor.get().isAppBackground) {
-                    ActivityUtil.moveToFront(context)
-                }
-                // 再通知Flutter进行页面跳转
-                JumpHostAppPageUtil.jumpAppPage(params, flutterEngine)
-            } else {
-                // 如果没有Activity,则通过原生Activity跳转
-                val intent = buildIntent(params, offAll)
+            val newTask = ActivityUtil.isDestroy(currentActivity)
+
+//            if (currentActivity != null && flutterEngine != null) {
+//                // 如果App在后台,则将App移动到前台
+//                if (AppMonitor.get().isAppBackground) {
+//                    ActivityUtil.moveToFront(context)
+//                }
+//                // 再通知Flutter进行页面跳转
+//                JumpHostAppPageUtil.jumpAppPage(params, flutterEngine)
+//            } else {
+//                // 如果没有Activity,则通过原生Activity跳转
+//                val intent = buildIntent(params, offAll)
+//                Utils.getApp().startActivity(intent)
+//            }
+
+            val intent = buildIntent(params, offAll, newTask)
+            if (newTask) {
                 Utils.getApp().startActivity(intent)
+            } else {
+                currentActivity.startActivity(intent)
             }
         }
 
@@ -92,11 +101,11 @@ class FlutterPageLaunchUtil private constructor() {
          */
         private fun buildIntent(
             params: Map<String, Serializable?> = mapOf<String, Serializable>(),
-            offAll: Boolean = false
+            offAll: Boolean = false,
+            newTask: Boolean = false
         ): Intent {
             val intent: Intent = IntentUtils.getLaunchAppIntent(Utils.getApp().packageName)
-            val currentActivity = ActivityProvider.get().currentActivity
-            if (currentActivity == null) {
+            if (newTask) {
                 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
             }
             if (offAll) {