{"record":{"id":"b661316ee58999d8","repo":"Tencent/matrix","slug":"not-initialized-yet-b66131","errorCode":null,"errorMessage":"NOT initialized yet","messagePattern":"NOT initialized yet","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/owners/ProcessUILifecycleOwner.kt","lineNumber":365,"sourceCode":"            } else {\n                false\n            }\n            val t = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {\n                isComponentOfProcess(this.topActivity, processName)\n            } else {\n                false\n            }\n\n            i || o || b || t\n        } else {\n            false\n        }\n    }\n\n    @JvmStatic\n    fun hasRunningAppTask(): Boolean {\n        if (activityManager == null) {\n            throw IllegalStateException(\"NOT initialized yet\")\n        }\n        return safeLet(TAG, defVal = true) {\n            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {\n                activityManager!!.appTasks\n                    .filter {\n                        it.taskInfo.belongsTo(processName)\n                    }.onEach {\n                        MatrixLog.i(TAG, \"$processName task: ${it.taskInfo.contentToString()}\")\n                    }.any {\n                        MatrixLog.d(TAG, \"hasRunningAppTask run any\")\n                        when {\n                            Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> {\n                                it.taskInfo.isRunning\n                            }\n                            Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {\n                                it.taskInfo.numActivities > 0\n                            }\n                            else -> {","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/lifecycle/owners/ProcessUILifecycleOwner.kt#L347-L383","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nval running = ProcessUILifecycleOwner.hasRunningAppTask()\n// after\nif (Matrix.isInstalled()) {\n    val running = ProcessUILifecycleOwner.hasRunningAppTask()\n} else {\n    ProcessLifecycleManager.init(application)\n}","handlingStrategy":"validation","validationCode":"if (!Matrix.isInstalled()) { ProcessLifecycleManager.init(application) }\nval running = ProcessUILifecycleOwner.hasRunningAppTask()","typeGuard":"fun canQueryAppTasks(): Boolean = Matrix.isInstalled()\ninline fun hasRunningAppTaskSafe(): Boolean =\n    if (canQueryAppTasks()) ProcessUILifecycleOwner.hasRunningAppTask() else false","tryCatchPattern":"val running = try {\n    ProcessUILifecycleOwner.hasRunningAppTask()\n} catch (e: IllegalStateException) {\n    MatrixLog.w(TAG, \"UI lifecycle not initialized\", e)\n    false\n}","preventionTips":["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."],"tags":["android","lifecycle","initialization-order","illegal-state"],"backgroundTag":"module-init-failed","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}