Skip to content

Commit 36254e8

Browse files
sumeruchatevantk91
andauthored
MOB-11639 Background Initialization (#946)
* ANR Solution * Fixes * Refactor * Refactor * Fix styling * Refactor * Update README * Attempt to fix * Attempt to fix * Attempt to fix * Attempt to fix * Attempt to fix * Attempt to fix * style * Further fix * Further fix * Further fix * Further fix * Further fix * Further fix * Further fix * Fixes from PR Review * Fixes from PR Review * Fixes from PR Review * Fixes from PR Review * Revert file * Revert file * Add background initialization to samole app --------- Co-authored-by: Evan Takeo Kanaiaupuni Greer <[email protected]>
1 parent 1a5cb2c commit 36254e8

File tree

15 files changed

+2466
-51
lines changed

15 files changed

+2466
-51
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,34 @@ To learn more about various SDK features, read:
3737
- [Embedded Messages with Iterable's Android SDK](https://support.iterable.com/hc/articles/23061877893652)
3838
- [Unknown User Activation: Developer Docs](https://support.iterable.com/hc/sections/40078809116180)
3939

40+
## Background Initialization (Recommended)
41+
42+
To prevent ANRs during app startup, use background initialization instead of the standard `initialize()` method:
43+
44+
```kotlin
45+
// In Application.onCreate()
46+
IterableApi.initializeInBackground(this, "your-api-key", config) {
47+
// SDK is ready - this callback is optional
48+
}
49+
```
50+
51+
**For subscribing to initialization completion from multiple places:**
52+
53+
```kotlin
54+
IterableApi.onSDKInitialized {
55+
// This callback will be invoked when initialization completes
56+
// If already initialized, it's called immediately
57+
}
58+
```
59+
60+
Background initialization prevents ANRs by:
61+
- Running all initialization work on a background thread
62+
- Automatically queuing API calls until initialization completes
63+
- Ensuring no data is lost during startup
64+
- Providing callbacks on the main thread when ready
65+
66+
**⚠️ Important:** Always wait for initialization completion before accessing SDK internals. Accessing the SDK internals before initialization completes can cause crashes. Use the callback methods above to ensure the SDK is ready before use.
67+
4068
## Sample projects
4169

4270
For sample code, take a look at:

iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java

Lines changed: 169 additions & 47 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)