|
1 | 1 | package com.example.confidence_flutter_sdk
|
2 | 2 |
|
3 | 3 | import android.content.Context
|
| 4 | +import androidx.lifecycle.LifecycleObserver |
| 5 | +import com.spotify.confidence.AndroidLifecycleEventProducer |
4 | 6 | import com.spotify.confidence.Confidence
|
5 | 7 | import com.spotify.confidence.ConfidenceFactory
|
6 | 8 | import com.spotify.confidence.ConfidenceValue
|
@@ -32,6 +34,7 @@ class ConfidenceFlutterSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAwar
|
32 | 34 | private lateinit var confidence: Confidence
|
33 | 35 | private val coroutineScope = CoroutineScope(Dispatchers.IO)
|
34 | 36 | private lateinit var context: Context
|
| 37 | + private lateinit var application: android.app.Application |
35 | 38 |
|
36 | 39 | override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
37 | 40 | channel = MethodChannel(flutterPluginBinding.binaryMessenger, "confidence_flutter_sdk")
|
@@ -69,6 +72,14 @@ class ConfidenceFlutterSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAwar
|
69 | 72 | val isEmpty = confidence.isStorageEmpty()
|
70 | 73 | result.success(isEmpty)
|
71 | 74 | }
|
| 75 | + "trackApplicationLifecycleState" -> { |
| 76 | + confidence.track( |
| 77 | + AndroidLifecycleEventProducer( |
| 78 | + application = application, |
| 79 | + trackActivities = true |
| 80 | + )) |
| 81 | + result.success(null) |
| 82 | + } |
72 | 83 | "getString" -> {
|
73 | 84 | val key = call.argument<String>("key")!!
|
74 | 85 | val defaultValue = call.argument<String>("defaultValue")
|
@@ -138,6 +149,7 @@ class ConfidenceFlutterSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAwar
|
138 | 149 |
|
139 | 150 | override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
140 | 151 | context = binding.activity.applicationContext
|
| 152 | + application = binding.activity.application |
141 | 153 | }
|
142 | 154 |
|
143 | 155 | override fun onDetachedFromActivityForConfigChanges() {
|
|
0 commit comments