amplitude / amplitude/Amplitude-Flutter

Only complete initialization after userId is properly set

Open
#188 2 comments 0 reactions 0 assignees View on GitHub
feature request
Dominant language
Dart
Stars
133
Forks
108
PR merge metrics
No merged PRs in 30d

Description

## Summary

Currently, if we initialize the plugin via `Amplitude.getInstance()` and try to get userId from it via `Amplitude.getInstance().getUserId()` right after, the userId is not set yet, because the initialization happens in a background thread and there is not a proper way to know when it is completed.

I've seen a `initCompletionBlock` that can be used for that on the iOS SDK, but I couldn't find one in the Android one. So maybe a change on the Android SDK would also be needed to achieve this.

## Motivations

Since we don't know when the userId will be ready, we need to wait some arbitrary amount of time. Since we use the presence of the userId to make some initialization decisions, if by any reason the amplitude initialization takes longer (e.g. some database migration), we will take the wrong initialization route.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.