File tree Expand file tree Collapse file tree
app/src/main/kotlin/com/google/ai/sample Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com.google.ai.sample
2+
3+ import kotlinx.coroutines.CoroutineExceptionHandler
4+ import kotlinx.coroutines.CoroutineScope
5+ import kotlinx.coroutines.Dispatchers
6+ import kotlinx.coroutines.SupervisorJob
7+ import android.app.Application
8+ import android.util.Log
9+
10+ /* *
11+ * Application class for maintaining application-wide state and resources
12+ */
13+ class PhotoReasoningApplication : Application () {
14+
15+ companion object {
16+ private const val TAG = " PhotoReasoningApp"
17+
18+ // Application-wide CoroutineScope that is not tied to any lifecycle
19+ // This scope will continue to run even when the app is in the background
20+ val applicationScope = CoroutineScope (
21+ SupervisorJob () +
22+ Dispatchers .Default +
23+ CoroutineExceptionHandler { _, throwable ->
24+ Log .e(TAG , " Uncaught exception in application scope: ${throwable.message} " , throwable)
25+ }
26+ )
27+
28+ // Instance of the application for global access
29+ private lateinit var instance: PhotoReasoningApplication
30+
31+ fun getInstance (): PhotoReasoningApplication {
32+ return instance
33+ }
34+ }
35+
36+ override fun onCreate () {
37+ super .onCreate()
38+ instance = this
39+ Log .d(TAG , " Application created" )
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments