improved loading time pwa/ct; removed splash screens
This commit is contained in:
@@ -20,10 +20,10 @@
|
||||
package eu.weblibre.gecko
|
||||
|
||||
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.embedding.engine.dart.DartExecutor
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
class MainActivity: FlutterFragmentActivity() {
|
||||
@@ -41,8 +41,21 @@ class MainActivity: FlutterFragmentActivity() {
|
||||
channel.invokeMethod("onTrimMemory", level)
|
||||
}
|
||||
|
||||
override fun getCachedEngineId(): String {
|
||||
return "engine_id"
|
||||
override fun provideFlutterEngine(context: Context): FlutterEngine {
|
||||
val cache = FlutterEngineCache.getInstance()
|
||||
val cachedEngine = cache.get("engine_id")
|
||||
if (cachedEngine != null) {
|
||||
return cachedEngine
|
||||
}
|
||||
|
||||
val flutterEngine = FlutterEngine(context.applicationContext)
|
||||
flutterEngine.navigationChannel.setInitialRoute("/")
|
||||
flutterEngine.dartExecutor.executeDartEntrypoint(
|
||||
DartExecutor.DartEntrypoint.createDefault()
|
||||
)
|
||||
cache.put("engine_id", flutterEngine)
|
||||
|
||||
return flutterEngine
|
||||
}
|
||||
|
||||
override fun shouldDestroyEngineWithHost(): Boolean {
|
||||
|
||||
@@ -19,47 +19,10 @@
|
||||
*/
|
||||
package eu.weblibre.gecko
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user