diff --git a/app/android/app/src/main/AndroidManifest.xml b/app/android/app/src/main/AndroidManifest.xml
index 9bb129dd..c893aa0e 100644
--- a/app/android/app/src/main/AndroidManifest.xml
+++ b/app/android/app/src/main/AndroidManifest.xml
@@ -6,6 +6,7 @@
+
@@ -50,7 +51,7 @@
diff --git a/app/android/app/src/main/kotlin/me/movenext/bang_navigator/MainActivity.kt b/app/android/app/src/main/kotlin/me/movenext/bang_navigator/MainActivity.kt
index 6e918134..9f0af2e7 100644
--- a/app/android/app/src/main/kotlin/me/movenext/bang_navigator/MainActivity.kt
+++ b/app/android/app/src/main/kotlin/me/movenext/bang_navigator/MainActivity.kt
@@ -1,7 +1,10 @@
package me.movenext.bang_navigator
+import android.content.Context
+import android.os.Bundle
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
+import io.flutter.embedding.engine.FlutterEngineCache
import io.flutter.plugin.common.MethodChannel
class MainActivity: FlutterFragmentActivity() {
@@ -10,6 +13,7 @@ class MainActivity: FlutterFragmentActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
+
channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
}
@@ -17,4 +21,12 @@ class MainActivity: FlutterFragmentActivity() {
super.onTrimMemory(level)
channel.invokeMethod("onTrimMemory", level)
}
+
+ override fun getCachedEngineId(): String {
+ return "engine_id"
+ }
+
+ override fun shouldDestroyEngineWithHost(): Boolean {
+ return false // Keep engine alive when activity is destroyed
+ }
}
diff --git a/app/android/app/src/main/kotlin/me/movenext/bang_navigator/MyApplication.kt b/app/android/app/src/main/kotlin/me/movenext/bang_navigator/MyApplication.kt
new file mode 100644
index 00000000..f821e99b
--- /dev/null
+++ b/app/android/app/src/main/kotlin/me/movenext/bang_navigator/MyApplication.kt
@@ -0,0 +1,46 @@
+package me.movenext.bang_navigator
+
+import android.app.ActivityManager
+import android.app.Application
+import android.content.Context
+import android.util.Log
+import io.flutter.embedding.engine.FlutterEngine
+import io.flutter.embedding.engine.FlutterEngineCache
+import io.flutter.embedding.engine.dart.DartExecutor
+
+class MyApplication : Application() {
+ private fun getProcessNameCompat(): String {
+ // Try to get process name from ActivityManager
+ val pid = android.os.Process.myPid()
+ val manager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
+
+ for (processInfo in manager.runningAppProcesses) {
+ if (processInfo.pid == pid) {
+ return processInfo.processName
+ }
+ }
+
+ // Fallback to package name if process name cannot be determined
+ return packageName
+ }
+
+ override fun onCreate() {
+ super.onCreate()
+
+ val processName = getProcessNameCompat()
+ // Only initialize Flutter engine in the main process
+ if (processName == packageName) {
+ // Initialize the Flutter engine
+ val flutterEngine = FlutterEngine(this)
+
+ // Pre-warm the Flutter engine with your initial route
+ flutterEngine.navigationChannel.setInitialRoute("/")
+ flutterEngine.dartExecutor.executeDartEntrypoint(
+ DartExecutor.DartEntrypoint.createDefault()
+ )
+
+ // Cache the Flutter engine
+ FlutterEngineCache.getInstance().put("engine_id", flutterEngine)
+ }
+ }
+}
\ No newline at end of file