You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PatientApp-KKUMC/android/app/src/main/java/com/cloud/diplomaticquarterapp/FlutterMainActivity.kt

93 lines
2.9 KiB
Kotlin

5 years ago
package com.cloud.diplomaticquarterapp
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.cloud.diplomaticquarterapp.utils.PlatformBridge
import io.flutter.embedding.android.FlutterView
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.dart.DartExecutor
import io.flutter.plugin.common.MethodChannel
import io.flutter.view.FlutterMain
import java.util.ArrayList
class FlutterMainActivity : BaseActivity() {
5 years ago
private var flutterView: FlutterView? = null
companion object {
private var flutterEngine: FlutterEngine? = null
private lateinit var instance:FlutterMainActivity
fun getInstance() : FlutterMainActivity{
return instance
}
5 years ago
}
// to get and check returned intent
private fun getArgsFromIntent(intent: Intent): Array<String>? {
// Before adding more entries to this list, consider that arbitrary
// Android applications can generate intents with extra data and that
// there are many security-sensitive args in the binary.
val args = ArrayList<String>()
if (intent.getBooleanExtra("trace-startup", false)) {
args.add("--trace-startup")
}
if (intent.getBooleanExtra("start-paused", false)) {
args.add("--start-paused")
}
if (intent.getBooleanExtra("enable-dart-profiling", false)) {
args.add("--enable-dart-profiling")
}
if (!args.isEmpty()) {
return args.toTypedArray()
}
return null
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val args = getArgsFromIntent(intent)
// check if flutterEngine is null
if (flutterEngine == null) {
println(args)
flutterEngine = FlutterEngine(this, args)
flutterEngine!!.dartExecutor.executeDartEntrypoint(
// set which of dart methode will be used here
DartExecutor.DartEntrypoint(FlutterMain.findAppBundlePath(), "main")
)
}
setContentView(R.layout.activity_flutter_main)
flutterView = findViewById(R.id.flutterView)
flutterView!!.attachToFlutterEngine(flutterEngine!!)
PlatformBridge(flutterEngine!!.dartExecutor.binaryMessenger, this).create()
}
override fun onResume() {
super.onResume()
flutterEngine!!.lifecycleChannel.appIsResumed()
instance = this
5 years ago
}
override fun onPause() {
super.onPause()
flutterEngine!!.lifecycleChannel.appIsInactive()
}
override fun onStop() {
super.onStop()
flutterEngine!!.lifecycleChannel.appIsPaused()
}
override fun onDestroy() {
flutterView!!.detachFromFlutterEngine()
super.onDestroy()
}
}