Fixed
Status Update
Comments
ki...@google.com <ki...@google.com>
jp...@gmail.com <jp...@gmail.com> #2
Or when changing to textView.textMetricsParamsCompat still crash.
private fun setAsyncText(textView: AppCompatTextView, text: String?) {
if (!text.isNullOrEmpty()) {
val textFuture = PrecomputedTextCompat.getTextFuture(text!!, textView.textMetricsParamsCompat, null)
textView.setTextFuture(textFuture) //Crash
}
}
private fun setAsyncText(textView: AppCompatTextView, text: String?) {
if (!text.isNullOrEmpty()) {
val textFuture = PrecomputedTextCompat.getTextFuture(text!!, textView.textMetricsParamsCompat, null)
textView.setTextFuture(textFuture) //Crash
}
}
al...@google.com <al...@google.com> #3
add this line :
textView.setLayoutDirection(ViewCompat.getLayoutDirection(textView));
before :
setTextFuture(....)
textView.setLayoutDirection(ViewCompat.getLayoutDirection(textView));
before :
setTextFuture(....)
al...@google.com <al...@google.com> #4
Thanks, #3. It worked.
But I think it is better when set before this line
val textFuture = PrecomputedTextCompat.getTextFuture(text!!, textView.textMetricsParamsCompat, null)
Set android:layoutDirection="locale" or android:layoutDirection="inherit" for AppCompatTextView in the XML layout didn't this problem.
The new method btw re-set layoutDirector. Weird! This should handle in the AppcompatTextView.
private fun setAsyncText(textView: AppCompatTextView, text: String?) {
if (!text.isNullOrEmpty()) {
textView.layoutDirection = textView.layoutDirection
val textFuture = PrecomputedTextCompat.getTextFuture(text!!, textView.textMetricsParamsCompat, null)
textView.setTextFuture(textFuture) //Crash
}
}
But I think it is better when set before this line
val textFuture = PrecomputedTextCompat.getTextFuture(text!!, textView.textMetricsParamsCompat, null)
Set android:layoutDirection="locale" or android:layoutDirection="inherit" for AppCompatTextView in the XML layout didn't this problem.
The new method btw re-set layoutDirector. Weird! This should handle in the AppcompatTextView.
private fun setAsyncText(textView: AppCompatTextView, text: String?) {
if (!text.isNullOrEmpty()) {
textView.layoutDirection = textView.layoutDirection
val textFuture = PrecomputedTextCompat.getTextFuture(text!!, textView.textMetricsParamsCompat, null)
textView.setTextFuture(textFuture) //Crash
}
}
al...@google.com <al...@google.com> #5
Sorry. I forgot the info.
minSdk 21
targetSdk 28
Thanks #3 again.
minSdk 21
targetSdk 28
Thanks #3 again.
al...@google.com <al...@google.com> #6
App Crash at
TextViewCompat.java:889
if (!param.equals(precomputed.getParams())) {
throw new IllegalArgumentException("Given text can not be applied to TextView.");
}
PrecomputedTextCompat.class:334
with : this.mTextDir != other.getTextDirection() == true
So,
TextDirection on TextView and TextDirection on Param is difference
maybe, it handled wrong or missing conditional on getTextDirectionHeuristic of TextViewCompat
TextViewCompat.java:889
if (!param.equals(precomputed.getParams())) {
throw new IllegalArgumentException("Given text can not be applied to TextView.");
}
PrecomputedTextCompat.class:334
with : this.mTextDir != other.getTextDirection() == true
So,
TextDirection on TextView and TextDirection on Param is difference
maybe, it handled wrong or missing conditional on getTextDirectionHeuristic of TextViewCompat
al...@google.com <al...@google.com> #7
With reference to comment #4 , issue is resolved by implementing suggested changes in comment #3 . Can you please confirm if we need to still investigate this issue ?
al...@google.com <al...@google.com> #8
Yes. textView.layoutDirection = textView.layoutDirection(>= API17) or ViewCompat.setLayoutDirection(textView, ViewCompat.getLayoutDirection(textView)) will resolve this bug.
But I think you should handle it in the AppcompatTextView. It is better. If a developer forgets testing with RTL. I think this is the nightmare(it is difficult to determine the bug) when they update their app on the Play Store.
I read this article, in the part databing he noted about set the direction
https://medium.com/google-developers/prefetch-text-layout-in-recyclerview-4acf9103f438 '
fun asyncText
..........
// first, set all measurement affecting properties of the text
// (size, locale, typeface, direction, etc)
But in the offical document isn't good (lack direction)
https://developer.android.com/reference/androidx/appcompat/widget/AppCompatTextView.html#setTextFuture(java.util.concurrent.Future%3Candroidx.core.text.PrecomputedTextCompat%3E)
Anything layout related property changes, text size, typeface, letter spacing, etc after this method call will causes IllegalArgumentException during View measurement.
My view: Handling this in the AppcompatTextView is the best choice if you can do it.
Thanks!
But I think you should handle it in the AppcompatTextView. It is better. If a developer forgets testing with RTL. I think this is the nightmare(it is difficult to determine the bug) when they update their app on the Play Store.
I read this article, in the part databing he noted about set the direction
fun asyncText
..........
// first, set all measurement affecting properties of the text
// (size, locale, typeface, direction, etc)
But in the offical document isn't good (lack direction)
Anything layout related property changes, text size, typeface, letter spacing, etc after this method call will causes IllegalArgumentException during View measurement.
My view: Handling this in the AppcompatTextView is the best choice if you can do it.
Thanks!
al...@google.com <al...@google.com> #9
I think should handle setLayoutDirection in the AppcompatTextView when setTextFuture, it will simpler for dev when implement TextFuture.
al...@google.com <al...@google.com> #10
We have passed this to the development team and will update this issue with more information as it becomes available.
al...@google.com <al...@google.com> #11
Fix released with appCompat 1.0.2, core 1.0.1
al...@google.com <al...@google.com> #12
Similar request has been raised in another bug in Android AOSP external tracker in b/123131632 .
Description shared by an external reporter:
================================
1.
Version used: androidx.appcompat:appcompat:1.1.0-alpha1
AppCompatTextView.setTextFuture
http://crashes.to/s/a9335204277
i foundhttps://issuetracker.google.com/issues/113070424 say version 1.0.2 fixed, But it still exists。
2.
Non-fatal Exception: java.lang.IllegalArgumentException: Given text can not be applied to TextView.
at androidx.core.widget.TextViewCompat.retrieveField(Unknown Source:22)
at androidx.appcompat.widget.AppCompatTextView.consumeTextFutureAndSetBlocking(Unknown Source:15)
at androidx.appcompat.widget.AppCompatTextView.onMeasure(Unknown Source)
at com.bilibili.magicasakura.widgets.AppCompatTintTextView.onMeasure(Unknown Source)
at android.view.View.measure(View.java:22145)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22145)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.cardview.widget.CardView.onMeasure(Unknown Source:80)
at android.view.View.measure(View.java:22145)
at androidx.recyclerview.widget.RecyclerView$LayoutManager.measureChildWithMargins(Unknown Source:98)
at androidx.recyclerview.widget.LinearLayoutManager.generateDefaultLayoutParams(Unknown Source:60)
at androidx.recyclerview.widget.LinearLayoutManager.generateDefaultLayoutParams(Unknown Source:44)
at androidx.recyclerview.widget.LinearLayoutManager.findViewByPosition(Unknown Source:36)
at androidx.recyclerview.widget.LinearLayoutManager.setOrientation(Unknown Source:6)
at androidx.recyclerview.widget.RecyclerView.exceptionLabel(Unknown Source:39)
at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(Unknown Source:91)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:979)
at android.view.Choreographer.doCallbacks(Choreographer.java:791)
at android.view.Choreographer.doFrame(Choreographer.java:723)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:965)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6707)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:108)
device: meizu, Android 7 and 8
And you can see fabric detailhttp://crashes.to/s/a9335204277
===========================================
Requesting team for initial inputs. Please let us know if this can be handled as a part of this bug else we will create a separate bug for this.
Description shared by an external reporter:
================================
1.
Version used: androidx.appcompat:appcompat:1.1.0-alpha1
AppCompatTextView.setTextFuture
i found
2.
Non-fatal Exception: java.lang.IllegalArgumentException: Given text can not be applied to TextView.
at androidx.core.widget.TextViewCompat.retrieveField(Unknown Source:22)
at androidx.appcompat.widget.AppCompatTextView.consumeTextFutureAndSetBlocking(Unknown Source:15)
at androidx.appcompat.widget.AppCompatTextView.onMeasure(Unknown Source)
at com.bilibili.magicasakura.widgets.AppCompatTintTextView.onMeasure(Unknown Source)
at android.view.View.measure(View.java:22145)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22145)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.cardview.widget.CardView.onMeasure(Unknown Source:80)
at android.view.View.measure(View.java:22145)
at androidx.recyclerview.widget.RecyclerView$LayoutManager.measureChildWithMargins(Unknown Source:98)
at androidx.recyclerview.widget.LinearLayoutManager.generateDefaultLayoutParams(Unknown Source:60)
at androidx.recyclerview.widget.LinearLayoutManager.generateDefaultLayoutParams(Unknown Source:44)
at androidx.recyclerview.widget.LinearLayoutManager.findViewByPosition(Unknown Source:36)
at androidx.recyclerview.widget.LinearLayoutManager.setOrientation(Unknown Source:6)
at androidx.recyclerview.widget.RecyclerView.exceptionLabel(Unknown Source:39)
at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(Unknown Source:91)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:979)
at android.view.Choreographer.doCallbacks(Choreographer.java:791)
at android.view.Choreographer.doFrame(Choreographer.java:723)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:965)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6707)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:108)
device: meizu, Android 7 and 8
And you can see fabric detail
===========================================
Requesting team for initial inputs. Please let us know if this can be handled as a part of this bug else we will create a separate bug for this.
ap...@google.com <ap...@google.com> #14
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 42808e39fb69f457e1d3d07237425c3df9416c26
Author: Alan Viverette <alanv@google.com>
Date: Wed Jul 29 16:05:48 2020
Ensure that ActivityCompat.recreate() works from onResume on SDK <= 23
Adds tests for onResume, onStart, and onStop that verify behavior across
all API levels.
Relnote: "Allow ActivityCompat.recreate() to be safely called from any
lifecycle state on any API level."
Bug: 160122826
Test: ActivityCompatRecreateFromLifecycleStatesTest
Change-Id: I62dde2d9041eb5b7ba2344380841aa03848d42e0
M core/core/src/androidTest/AndroidManifest.xml
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateFromResumeTestCase.kt
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateLifecycleTestActivity.kt
M core/core/src/main/java/androidx/core/app/ActivityCompat.java
M core/core/src/main/java/androidx/core/app/ActivityRecreator.java
https://android-review.googlesource.com/1383907
Branch: androidx-master-dev
commit 42808e39fb69f457e1d3d07237425c3df9416c26
Author: Alan Viverette <alanv@google.com>
Date: Wed Jul 29 16:05:48 2020
Ensure that ActivityCompat.recreate() works from onResume on SDK <= 23
Adds tests for onResume, onStart, and onStop that verify behavior across
all API levels.
Relnote: "Allow ActivityCompat.recreate() to be safely called from any
lifecycle state on any API level."
Bug: 160122826
Test: ActivityCompatRecreateFromLifecycleStatesTest
Change-Id: I62dde2d9041eb5b7ba2344380841aa03848d42e0
M core/core/src/androidTest/AndroidManifest.xml
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateFromResumeTestCase.kt
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateLifecycleTestActivity.kt
M core/core/src/main/java/androidx/core/app/ActivityCompat.java
M core/core/src/main/java/androidx/core/app/ActivityRecreator.java
ap...@google.com <ap...@google.com> #15
Project: platform/frameworks/support
Branch: snap-temp-L43700000691908123
commit d99565ea445577278517dc13a6783b68f8fec238
Author: Alan Viverette <alanv@google.com>
Date: Wed Jul 29 16:05:48 2020
Ensure that ActivityCompat.recreate() works from onResume on SDK <= 23
Adds tests for onResume, onStart, and onStop that verify behavior across
all API levels.
Relnote: "Allow ActivityCompat.recreate() to be safely called from any
lifecycle state on any API level."
Bug: 160122826
Test: ActivityCompatRecreateFromLifecycleStatesTest
Change-Id: I62dde2d9041eb5b7ba2344380841aa03848d42e0
(cherry picked from commit 5dcfcd6b3593e8237ecb306053979433e75f9515)
M core/core/src/androidTest/AndroidManifest.xml
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateFromResumeTestCase.kt
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateLifecycleTestActivity.kt
M core/core/src/main/java/androidx/core/app/ActivityCompat.java
M core/core/src/main/java/androidx/core/app/ActivityRecreator.java
https://android-review.googlesource.com/1427108
Branch: snap-temp-L43700000691908123
commit d99565ea445577278517dc13a6783b68f8fec238
Author: Alan Viverette <alanv@google.com>
Date: Wed Jul 29 16:05:48 2020
Ensure that ActivityCompat.recreate() works from onResume on SDK <= 23
Adds tests for onResume, onStart, and onStop that verify behavior across
all API levels.
Relnote: "Allow ActivityCompat.recreate() to be safely called from any
lifecycle state on any API level."
Bug: 160122826
Test: ActivityCompatRecreateFromLifecycleStatesTest
Change-Id: I62dde2d9041eb5b7ba2344380841aa03848d42e0
(cherry picked from commit 5dcfcd6b3593e8237ecb306053979433e75f9515)
M core/core/src/androidTest/AndroidManifest.xml
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateFromResumeTestCase.kt
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateLifecycleTestActivity.kt
M core/core/src/main/java/androidx/core/app/ActivityCompat.java
M core/core/src/main/java/androidx/core/app/ActivityRecreator.java
ap...@google.com <ap...@google.com> #16
Project: platform/frameworks/support
Branch: snap-temp-L39700000691908325
commit facb88fa7f503056bbbd9284cdd58c22073f354a
Author: Alan Viverette <alanv@google.com>
Date: Wed Jul 29 16:05:48 2020
Ensure that ActivityCompat.recreate() works from onResume on SDK <= 23
Adds tests for onResume, onStart, and onStop that verify behavior across
all API levels.
Relnote: "Allow ActivityCompat.recreate() to be safely called from any
lifecycle state on any API level."
Bug: 160122826
Test: ActivityCompatRecreateFromLifecycleStatesTest
Change-Id: I62dde2d9041eb5b7ba2344380841aa03848d42e0
(cherry picked from commit 5dcfcd6b3593e8237ecb306053979433e75f9515)
M core/core/src/androidTest/AndroidManifest.xml
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateFromResumeTestCase.kt
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateLifecycleTestActivity.kt
M core/core/src/main/java/androidx/core/app/ActivityCompat.java
M core/core/src/main/java/androidx/core/app/ActivityRecreator.java
https://android-review.googlesource.com/1427111
Branch: snap-temp-L39700000691908325
commit facb88fa7f503056bbbd9284cdd58c22073f354a
Author: Alan Viverette <alanv@google.com>
Date: Wed Jul 29 16:05:48 2020
Ensure that ActivityCompat.recreate() works from onResume on SDK <= 23
Adds tests for onResume, onStart, and onStop that verify behavior across
all API levels.
Relnote: "Allow ActivityCompat.recreate() to be safely called from any
lifecycle state on any API level."
Bug: 160122826
Test: ActivityCompatRecreateFromLifecycleStatesTest
Change-Id: I62dde2d9041eb5b7ba2344380841aa03848d42e0
(cherry picked from commit 5dcfcd6b3593e8237ecb306053979433e75f9515)
M core/core/src/androidTest/AndroidManifest.xml
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateFromResumeTestCase.kt
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateLifecycleTestActivity.kt
M core/core/src/main/java/androidx/core/app/ActivityCompat.java
M core/core/src/main/java/androidx/core/app/ActivityRecreator.java
ap...@google.com <ap...@google.com> #17
Project: platform/frameworks/support
Branch: snap-temp-L39600000691945594
commit 09508097fd54b56c93298563e880862ba8d8944d
Author: Alan Viverette <alanv@google.com>
Date: Wed Jul 29 16:05:48 2020
Ensure that ActivityCompat.recreate() works from onResume on SDK <= 23
Adds tests for onResume, onStart, and onStop that verify behavior across
all API levels.
Relnote: "Allow ActivityCompat.recreate() to be safely called from any
lifecycle state on any API level."
Bug: 160122826
Test: ActivityCompatRecreateFromLifecycleStatesTest
Change-Id: I62dde2d9041eb5b7ba2344380841aa03848d42e0
(cherry picked from commit 5dcfcd6b3593e8237ecb306053979433e75f9515)
M core/core/src/androidTest/AndroidManifest.xml
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateFromResumeTestCase.kt
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateLifecycleTestActivity.kt
M core/core/src/main/java/androidx/core/app/ActivityCompat.java
M core/core/src/main/java/androidx/core/app/ActivityRecreator.java
https://android-review.googlesource.com/1427268
Branch: snap-temp-L39600000691945594
commit 09508097fd54b56c93298563e880862ba8d8944d
Author: Alan Viverette <alanv@google.com>
Date: Wed Jul 29 16:05:48 2020
Ensure that ActivityCompat.recreate() works from onResume on SDK <= 23
Adds tests for onResume, onStart, and onStop that verify behavior across
all API levels.
Relnote: "Allow ActivityCompat.recreate() to be safely called from any
lifecycle state on any API level."
Bug: 160122826
Test: ActivityCompatRecreateFromLifecycleStatesTest
Change-Id: I62dde2d9041eb5b7ba2344380841aa03848d42e0
(cherry picked from commit 5dcfcd6b3593e8237ecb306053979433e75f9515)
M core/core/src/androidTest/AndroidManifest.xml
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateFromResumeTestCase.kt
A core/core/src/androidTest/java/androidx/core/app/ActivityCompatRecreateLifecycleTestActivity.kt
M core/core/src/main/java/androidx/core/app/ActivityCompat.java
M core/core/src/main/java/androidx/core/app/ActivityRecreator.java
an...@google.com <an...@google.com> #18
The following changes were cherrypicked through
Release Track:
Changes: aosp/1426928
Description
On API 21, when
ActivityCompat.recreate()
is called fromActivity.onStart()
orActivity.onResume()
, the newly created activity becomes stuck on a black screen. However, callingActivity.recreate()
directly doesn't cause any issues.I've created a very simple sample project to reproduce the issue:https://github.com/jpmcosta/AndroidTestProject/tree/43793368a74f97fff17818ebb5455594910b3002
The first time you open the app it will try to recreate the activity using
ActivityCompat.recreate()
and it will show a black screen. You should go back and reopen the app.The second time you open the app (if the app's process is not killed) it will try to recreate the activity using
Activity.recreate()
directly and it will succeed in doing so.Component used: AppCompat
Version used: 1.3.0-alpha01
Devices/Android versions reproduced on: Emulator API 21