Fixed
Status Update
Comments
ra...@google.com <ra...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 6e8f6eba120ca0a2361a0e88184840cc090ee563
Author: Rahul Ravikumar <rahulrav@google.com>
Date: Mon Jul 27 10:39:09 2020
Add the ability to detemine if an `Initializer` was initialized eagerly.
* This is useful in the case where some `Initializer`s can only work correctly,
if they have been eagerly initialized. For e.g. use-cases like
observing process lifecycle or activity listeners require eager initialization.
* Using this API the `Initializer` can determine if it was eagerly
initialized, and throw an `Exception` otherwise.
Fixes: b/159952713
Test: Added unit tests.
Relnote: "Added a new `isEagerlyInitialized()` API which provides a way for the `Initializer`
to discover if has been being eagerly initialized."
Change-Id: I17cdd3b5eab6e656c0ce97c4ae6951664df325d6
M startup/startup-runtime/api/current.txt
M startup/startup-runtime/api/public_plus_experimental_current.txt
M startup/startup-runtime/api/restricted_current.txt
M startup/startup-runtime/src/androidTest/java/androidx/startup/AppInitializerTest.kt
M startup/startup-runtime/src/main/java/androidx/startup/AppInitializer.java
https://android-review.googlesource.com/1372879
Branch: androidx-master-dev
commit 6e8f6eba120ca0a2361a0e88184840cc090ee563
Author: Rahul Ravikumar <rahulrav@google.com>
Date: Mon Jul 27 10:39:09 2020
Add the ability to detemine if an `Initializer` was initialized eagerly.
* This is useful in the case where some `Initializer`s can only work correctly,
if they have been eagerly initialized. For e.g. use-cases like
observing process lifecycle or activity listeners require eager initialization.
* Using this API the `Initializer` can determine if it was eagerly
initialized, and throw an `Exception` otherwise.
Fixes:
Test: Added unit tests.
Relnote: "Added a new `isEagerlyInitialized()` API which provides a way for the `Initializer`
to discover if has been being eagerly initialized."
Change-Id: I17cdd3b5eab6e656c0ce97c4ae6951664df325d6
M startup/startup-runtime/api/current.txt
M startup/startup-runtime/api/public_plus_experimental_current.txt
M startup/startup-runtime/api/restricted_current.txt
M startup/startup-runtime/src/androidTest/java/androidx/startup/AppInitializerTest.kt
M startup/startup-runtime/src/main/java/androidx/startup/AppInitializer.java
lo...@gmail.com <lo...@gmail.com> #3
Thanks so much for adding the feature!
Description
Usage of the API can only work reliably if this function is called at app start.
registerActivityLifecycleCallbacks
Otherwise, some Activities might have been created, and there's no way for the app to know about it through public APIs and the callbacks that only dispatch changes but not current state at the time of registering.
I have a use case that involves knowing whether any of the Activities in the process is focused. This requires to get a reference to all resumed activities (there might be mutliple with multi-window on API 29+), and then check if one of them has its window focused (and listen to changes).
So, I'd like to receive on initialization whether the component that calls
registerActivityLifecycleCallbacks
was initialized on process creation, and throw if not, since it cannot work reliably if created after activities start being created.This would be a
Boolean
parameter in thecreate
function, namedprocessJustCreated
or alike.An alternative is to allow specifying that an initializer requires to start at app startup (but I'm worried this apporach might make it easier for some SDK vendors to abuse this when not really needed for the host apps).
A latter alternative is to have an AndroidX API (for API 18+) that exposes a reference to all the currently created Activities, along with their lifecycle, so I can get a property of type
Flow<Set<Pair<Activity, Lifecycle.State>>>
for my use case.