Skip to content

ANR with Statsig.shutdown() #25

@nominalista

Description

@nominalista

According to the docs, it's recommended to call Statsig.shutdown() when closing the app to make sure all events and logs are stored. However, such implementation causes ANR errors when the Activity is getting destroyed:

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initializeAnalytics()
        // setting up activity here
    }

    override fun onDestroy() {
        super.onDestroy()
        shutdownAnalytics()
    }

    private fun initializeAnalytics() {
        lifecycleScope.async {
            Statsig.initialize(application, STATSIG_SDK_KEY, StatsigUser())
            Log.d(TAG, "Statsig initialized")
        }
    }

    private fun shutdownAnalytics() {
        // Makes sure all logged events are properly flushed or saved locally
        Log.d(TAG, "Shutting down Statsig…")
        Statsig.shutdown()
    }

    // rest of the code…
}

Is this incorrect implementation or defect in 4.44.0?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions