File tree 1 file changed +13
-7
lines changed
core/src/main/java/com/amplitude/core/platform
1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -171,13 +171,19 @@ class EventPipeline(
171
171
172
172
private fun registerShutdownHook () {
173
173
// close the stream if the app shuts down
174
- Runtime .getRuntime().addShutdownHook(
175
- object : Thread () {
176
- override fun run () {
177
- this @EventPipeline.stop()
178
- }
179
- },
180
- )
174
+ try {
175
+ Runtime .getRuntime().addShutdownHook(
176
+ object : Thread () {
177
+ override fun run () {
178
+ this @EventPipeline.stop()
179
+ }
180
+ },
181
+ )
182
+ } catch (e: IllegalStateException ) {
183
+ // Once the shutdown sequence has begun it is impossible to register a shutdown hook,
184
+ // so we just ignore the IllegalStateException that's thrown.
185
+ // https://developer.android.com/reference/java/lang/Runtime#addShutdownHook(java.lang.Thread)
186
+ }
181
187
}
182
188
}
183
189
You can’t perform that action at this time.
0 commit comments