Skip to content

Commit

Permalink
App: Introduce the App class to provide global application states
Browse files Browse the repository at this point in the history
Several properties in the Application class are dynamically bound
after the application launches, which means accessing those properties
before bound incurs NPE. To avoid such unintended NPE, this patch
introduces the App singleton class holding those properties like
applicationContext.

Signed-off-by: Wook Song <[email protected]>
  • Loading branch information
wooksong committed Jun 3, 2024
1 parent 532bb30 commit f4a86eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ml_inference_offloading/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
<application android:name=".App"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ai.nnstreamer.ml.inference.offloading

import android.app.Application
import android.content.Context

class App : Application() {
init{
instance = this
}

companion object {
lateinit var instance: App

fun context() : Context {
return instance.applicationContext
}
}
}

0 comments on commit f4a86eb

Please sign in to comment.