Stats: считать запуском каждый выход на передний план

SvxApp.onCreate вызывается один раз на процесс, поэтому при живом
фоне повторные открытия не учитывались. Теперь считаем onStart
ProcessLifecycleOwner (холодный старт и каждое открытие приложения).
This commit is contained in:
ua1zbe
2026-10-09 14:03:25 +03:00
parent b6e4fb7e3a
commit 4e7bf86f37
2 changed files with 18 additions and 1 deletions

View File

@@ -44,6 +44,7 @@ kotlin {
dependencies {
implementation("ru.rustore.sdk:pushclient:7.4.0")
implementation("androidx.lifecycle:lifecycle-process:2.7.0")
testImplementation("junit:junit:4.13.2")
}

View File

@@ -4,6 +4,9 @@ import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import android.util.Log
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner
import ru.rustore.sdk.pushclient.RuStorePushClient
import ru.ua1zbe.svxremote.prefs.Prefs
@@ -17,7 +20,20 @@ class SvxApp : Application() {
super.onCreate()
createPushChannel()
initRuStorePush()
StatsReporter.report(this)
trackLaunches()
}
/**
* Считаем запуском каждый вывод приложения на передний план (холодный старт
* и повторное открытие), а не только создание процесса — иначе при живом
* процессе в фоне повторные открытия не учитывались бы.
*/
private fun trackLaunches() {
ProcessLifecycleOwner.get().lifecycle.addObserver(object : DefaultLifecycleObserver {
override fun onStart(owner: LifecycleOwner) {
StatsReporter.report(this@SvxApp)
}
})
}
private fun createPushChannel() {