Fixed
Status Update
Comments
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
Hi Ed, Thank you so much for these suggestions. I've been reviewing them and merging them in. Hopefully it should be live. I've included a thank you note too in the article.
ap...@google.com <ap...@google.com> #3
Great! Thanks a lot, I'll look for the live updates soon!
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 5d11382f47626211d512b9135f6b5f40b88f6647
Author: Ian Lake <ilake@google.com>
Date: Mon Aug 03 12:45:55 2020
Simplify OnContextAvailableListener interface
Rather than pass the ContextAware object,
the Context, and a Bundle for saved instance
state, pass only the Context to the
onContextAvailable() callback.
The ContextAware parameter is not needed in
general (unregistering is a corner case that
can be handled by capturing a reference to the
ContextAware).
The saved instance state Bundle is not needed
when we can ensure that the
SavedStateRegistry has had its state restored
before the listeners are called. This ensures
that all Saved State logic is centralized in
the API specifically built for saving state
rather than leaking into other APIs.
To accomplish this API change, the storage of
FragmentManager's and AppCompatDelegate's saved
state was moved to SavedStateRegistry as part of
FragmentActivity and AppCompatActivity,
respectively. Longer term, FragmentManager and
AppCompatDelegate should provide public APIs for
connecting directly to SavedStateRegistry, but
that is out of scope for this change.
Test: activity, fragment, and appcompat tests pass
BUG: 161390636
Relnote: N/A
Change-Id: I32fdd4b2c4c391c3fa97158dbd7508fa96b08d7a
M activity/activity/api/current.txt
M activity/activity/api/public_plus_experimental_current.txt
M activity/activity/api/restricted_current.txt
M activity/activity/src/androidTest/java/androidx/activity/ComponentActivityLifecycleTest.kt
M activity/activity/src/androidTest/java/androidx/activity/ComponentActivitySavedStateTest.kt
M activity/activity/src/androidTest/java/androidx/activity/contextaware/ContextAwareHelperTest.kt
M activity/activity/src/main/java/androidx/activity/ComponentActivity.java
M activity/activity/src/main/java/androidx/activity/contextaware/ContextAwareHelper.java
M activity/activity/src/main/java/androidx/activity/contextaware/OnContextAvailableListener.java
M appcompat/appcompat/src/main/java/androidx/appcompat/app/AppCompatActivity.java
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentArchLifecycleTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
https://android-review.googlesource.com/1385861
Branch: androidx-master-dev
commit 5d11382f47626211d512b9135f6b5f40b88f6647
Author: Ian Lake <ilake@google.com>
Date: Mon Aug 03 12:45:55 2020
Simplify OnContextAvailableListener interface
Rather than pass the ContextAware object,
the Context, and a Bundle for saved instance
state, pass only the Context to the
onContextAvailable() callback.
The ContextAware parameter is not needed in
general (unregistering is a corner case that
can be handled by capturing a reference to the
ContextAware).
The saved instance state Bundle is not needed
when we can ensure that the
SavedStateRegistry has had its state restored
before the listeners are called. This ensures
that all Saved State logic is centralized in
the API specifically built for saving state
rather than leaking into other APIs.
To accomplish this API change, the storage of
FragmentManager's and AppCompatDelegate's saved
state was moved to SavedStateRegistry as part of
FragmentActivity and AppCompatActivity,
respectively. Longer term, FragmentManager and
AppCompatDelegate should provide public APIs for
connecting directly to SavedStateRegistry, but
that is out of scope for this change.
Test: activity, fragment, and appcompat tests pass
BUG: 161390636
Relnote: N/A
Change-Id: I32fdd4b2c4c391c3fa97158dbd7508fa96b08d7a
M activity/activity/api/current.txt
M activity/activity/api/public_plus_experimental_current.txt
M activity/activity/api/restricted_current.txt
M activity/activity/src/androidTest/java/androidx/activity/ComponentActivityLifecycleTest.kt
M activity/activity/src/androidTest/java/androidx/activity/ComponentActivitySavedStateTest.kt
M activity/activity/src/androidTest/java/androidx/activity/contextaware/ContextAwareHelperTest.kt
M activity/activity/src/main/java/androidx/activity/ComponentActivity.java
M activity/activity/src/main/java/androidx/activity/contextaware/ContextAwareHelper.java
M activity/activity/src/main/java/androidx/activity/contextaware/OnContextAvailableListener.java
M appcompat/appcompat/src/main/java/androidx/appcompat/app/AppCompatActivity.java
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentArchLifecycleTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
ap...@google.com <ap...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-master-dev
commit d830158f1671930bab215716e329349a42eec1dd
Author: Ian Lake <ilake@google.com>
Date: Fri Jul 31 14:14:29 2020
Add suspending withContextAvailable to ContextAware
Expand the ContextAware interface to allow developers
to synchronously peek to see if the context is
availble.
This allows us to write a Kotlin extension
withContextAvailable() that runs a non-suspending
block once the context becomes available (either
synchronously if it is already available or by
using a OnContextAvailableListener under the hood
if not).
Test: new tests pass
BUG: 161390636
Relnote: "Added a `peekAvailableContext()` API to
`ContextAware` to allow you to synchronously determine
if a Context is available. A suspending Kotlin extension
`withContextAvailable()` allows you to run a
non-suspending block when the Context becomes available
and return a result."
Change-Id: I8290cd9de8231913036d23a233c177ed45d2d370
M activity/activity-ktx/api/current.txt
M activity/activity-ktx/api/public_plus_experimental_current.txt
M activity/activity-ktx/api/restricted_current.txt
A activity/activity-ktx/src/androidTest/java/androidx/activity/contextaware/ContextAwareTest.kt
A activity/activity-ktx/src/main/java/androidx/activity/contextaware/ContextAware.kt
M activity/activity/api/current.txt
M activity/activity/api/public_plus_experimental_current.txt
M activity/activity/api/restricted_current.txt
M activity/activity/src/androidTest/java/androidx/activity/contextaware/ContextAwareHelperTest.kt
M activity/activity/src/main/java/androidx/activity/ComponentActivity.java
M activity/activity/src/main/java/androidx/activity/contextaware/ContextAware.java
M activity/activity/src/main/java/androidx/activity/contextaware/ContextAwareHelper.java
https://android-review.googlesource.com/1384202
Branch: androidx-master-dev
commit d830158f1671930bab215716e329349a42eec1dd
Author: Ian Lake <ilake@google.com>
Date: Fri Jul 31 14:14:29 2020
Add suspending withContextAvailable to ContextAware
Expand the ContextAware interface to allow developers
to synchronously peek to see if the context is
availble.
This allows us to write a Kotlin extension
withContextAvailable() that runs a non-suspending
block once the context becomes available (either
synchronously if it is already available or by
using a OnContextAvailableListener under the hood
if not).
Test: new tests pass
BUG: 161390636
Relnote: "Added a `peekAvailableContext()` API to
`ContextAware` to allow you to synchronously determine
if a Context is available. A suspending Kotlin extension
`withContextAvailable()` allows you to run a
non-suspending block when the Context becomes available
and return a result."
Change-Id: I8290cd9de8231913036d23a233c177ed45d2d370
M activity/activity-ktx/api/current.txt
M activity/activity-ktx/api/public_plus_experimental_current.txt
M activity/activity-ktx/api/restricted_current.txt
A activity/activity-ktx/src/androidTest/java/androidx/activity/contextaware/ContextAwareTest.kt
A activity/activity-ktx/src/main/java/androidx/activity/contextaware/ContextAware.kt
M activity/activity/api/current.txt
M activity/activity/api/public_plus_experimental_current.txt
M activity/activity/api/restricted_current.txt
M activity/activity/src/androidTest/java/androidx/activity/contextaware/ContextAwareHelperTest.kt
M activity/activity/src/main/java/androidx/activity/ComponentActivity.java
M activity/activity/src/main/java/androidx/activity/contextaware/ContextAware.java
M activity/activity/src/main/java/androidx/activity/contextaware/ContextAwareHelper.java
il...@google.com <il...@google.com> #6
The new ContextAware
API will be available in Activity 1.2.0-alpha08 and is used by Fragment 1.3.0-alpha08 and AppCompat 1.3.0-alpha02 to implement FragmentManager's and AppCompatDelegate's pre-onCreate() logic.
e....@gmail.com <e....@gmail.com> #7
Wait, this can't work as advertised.
FragmentActivity extends ComponentActivity
public FragmentActivity(@LayoutRes int contentLayoutId) {
super(contentLayoutId);
init();
}
private void init() {
addOnContextAvailableListener(new OnContextAvailableListener() {
// ...
}
}
ComponentActivity
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
// ...
mContextAwareHelper.dispatchOnContextAvailable(this);
super.onCreate(savedInstanceState);
//...
}
- Call
FragmentActivity
constructor, - which calls
ComponentActivity
super constructor, - which dispatches context available... to noone,
- and calls platform Activity.onCreate.
- Bubble up to
FragmentActivity
constructor and register context listener, - which is invoked synchronously but only after platform
Activity.onCreate
has already been called.
Did I miss something? I'm confused.
e....@gmail.com <e....@gmail.com> #8
Never mind, constructor vs onCreate. :facepalm: Sorry.
il...@google.com <il...@google.com> #9
Re #8 - the fact that these are different things is indeed exactly why this API exists :)
Description
Component used: Activity Version used: 1.2.0-alpha06
The APIs of
LifecycleOwner
provide us with a callback for when you reach theCREATED
state, but for activities that is often after some critical code needs to run.For example:
setTheme
to reset your theme from a branded launch themesetLocalNightMode()
These all need to be called before
super.onCreate()
and specifically the inflation of any layout.It would be nice if there was a composable way to get a callback at that exact time without needing to manually add code to
onCreate()
(which, will fine for app code, is hard to do as a library).