Tencent/matrix · error · IllegalStateException
NOT initialized yet
Error message
NOT initialized yet
What it means
ProcessUILifecycleOwner caches an ActivityManager reference during initialization (via ProcessLifecycleManager.init). hasRunningAppTask() throws this IllegalStateException when that reference is still null, meaning the owner was never initialized in this process. The library throws eagerly rather than returning a misleading default value.
Solutions
- Initialize the UI lifecycle owner (ProcessLifecycleManager.init(application)) before any call to hasRunningAppTask(), ideally in Application.onCreate.
- Check ProcessUILifecycleOwner.isInstalled / Matrix.isInstalled and defer the query until init completes (e.g. wait for the lifecycle callback).
- If the call runs in a non-UI process, either install the owner there too or route the query through the supervisor process.
- Wrap the call in a null/init check and fall back to a safe default when the owner is not initialized.
Example fix
// before
val running = ProcessUILifecycleOwner.hasRunningAppTask()
// after
if (Matrix.isInstalled()) {
val running = ProcessUILifecycleOwner.hasRunningAppTask()
} else {
ProcessLifecycleManager.init(application)
} Defensive patterns
Strategy: validation
Validate before calling
if (!Matrix.isInstalled()) { ProcessLifecycleManager.init(application) }
val running = ProcessUILifecycleOwner.hasRunningAppTask() Type guard
fun canQueryAppTasks(): Boolean = Matrix.isInstalled()
inline fun hasRunningAppTaskSafe(): Boolean =
if (canQueryAppTasks()) ProcessUILifecycleOwner.hasRunningAppTask() else false Try / catch
val running = try {
ProcessUILifecycleOwner.hasRunningAppTask()
} catch (e: IllegalStateException) {
MatrixLog.w(TAG, "UI lifecycle not initialized", e)
false
} Prevention
- Initialize Matrix and the UI lifecycle owner in Application.onCreate before any dependent query.
- Centralize Matrix install in the app's base Application class so every process gets it.
- Add a startup assertion in debug builds that the owner is installed before lifecycle queries run.
When it happens
Trigger: Calling ProcessUILifecycleOwner.hasRunningAppTask() before ProcessLifecycleManager/ProcessUILifecycleOwner.init(application) has run in the current process, or when init was skipped because the process was not configured to install the UI lifecycle owner.
Common situations: Querying running app tasks from a content provider or Application.onCreate code path that runs before Matrix init; calling from a background/auxiliary process where the UI lifecycle owner is never installed; initialization order changed after a Matrix version upgrade.
Related errors
- NOT initialized yet
- NOT allow to observe with DESTROYED lifecycle owner
- Supervisor NOT initialized yet or Supervisor is disabled!!!
- not initialized yet !
- plugin start, but plugin has been already destroyed
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/b661316ee58999d8.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/owners/ProcessUILifecycleOwner.kt:365
} else {
false
}
val t = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
isComponentOfProcess(this.topActivity, processName)
} else {
false
}
i || o || b || t
} else {
false
}
}
@JvmStatic
fun hasRunningAppTask(): Boolean {
if (activityManager == null) {
throw IllegalStateException("NOT initialized yet")
}
return safeLet(TAG, defVal = true) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activityManager!!.appTasks
.filter {
it.taskInfo.belongsTo(processName)
}.onEach {
MatrixLog.i(TAG, "$processName task: ${it.taskInfo.contentToString()}")
}.any {
MatrixLog.d(TAG, "hasRunningAppTask run any")
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> {
it.taskInfo.isRunning
}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
it.taskInfo.numActivities > 0
}
else -> {View on GitHub (pinned to 3b8293bd65)