Skip to content

Commit bbe4a41

Browse files
Add files via upload
1 parent d2c1376 commit bbe4a41

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}

0 commit comments

Comments
 (0)