33 lines · 1.3 KB · KotlinRaw
package com.cottondb.androidimport android.app.Applicationimport androidx.lifecycle.DefaultLifecycleObserverimport androidx.lifecycle.LifecycleOwnerimport androidx.lifecycle.ProcessLifecycleOwnerclass CottonApplication : Application(), DefaultLifecycleObserver, com.cottondb.android.platform.ScheduledNotificationRuntime, com.cottondb.android.platform.AlarmDeliveryFailureReporter { lateinit var runtime: AppRuntime private set override fun onCreate() { super<Application>.onCreate() if (getProcessName() != packageName) return runtime = AppRuntime(this) com.cottondb.android.platform.AndroidReminderRuntime.onError = { message, _ -> runtime.reportPlatformError(message) } ProcessLifecycleOwner.get().lifecycle.addObserver(this) runtime.open() } override suspend fun reconcileScheduledNotifications() = runtime.reconcileScheduledNotifications() override fun reportAlarmDeliveryFailure(message: String) = runtime.reportPlatformError(message) override fun onStart(owner: LifecycleOwner) = runtime.foreground() override fun onStop(owner: LifecycleOwner) = runtime.background() override fun onTerminate() { if (::runtime.isInitialized) runtime.close() super.onTerminate() }}