Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit f796782ea16c76f151e7d7635945f2f27c1190a0
Author: Simon Schiller <simonschiller@users.noreply.github.com>
Date: Mon Mar 22 01:26:40 2021
[GH] [FragmentStrictMode] Detect calls to Fragment#setTargetFragment
## Proposed Changes
- Detect calls to `Fragment#setTargetFragment`
## Testing
Test: See `FragmentStrictModeTest#detectSetTargetFragment`
## Issues Fixed
Fixes: 153737745
This is an imported pull request fromhttps://github.com/androidx/androidx/pull/139 .
Resolves #139
Github-Pr-Head-Sha: 89c830c8fe9c487e0dd14087dc99a720496d5c0f
GitOrigin-RevId: e73f51cf62e973d664cdfd8193b830e24e007a7c
Change-Id: I3066e87ed7cfa2bda19089979c722f1efe4103cf
M fragment/fragment/api/public_plus_experimental_current.txt
M fragment/fragment/api/restricted_current.txt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/strictmode/FragmentStrictModeTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
M fragment/fragment/src/main/java/androidx/fragment/app/strictmode/FragmentStrictMode.java
A fragment/fragment/src/main/java/androidx/fragment/app/strictmode/TargetFragmentUsageViolation.java
https://android-review.googlesource.com/1640408
Branch: androidx-main
commit f796782ea16c76f151e7d7635945f2f27c1190a0
Author: Simon Schiller <simonschiller@users.noreply.github.com>
Date: Mon Mar 22 01:26:40 2021
[GH] [FragmentStrictMode] Detect calls to Fragment#setTargetFragment
## Proposed Changes
- Detect calls to `Fragment#setTargetFragment`
## Testing
Test: See `FragmentStrictModeTest#detectSetTargetFragment`
## Issues Fixed
Fixes: 153737745
This is an imported pull request from
Resolves #139
Github-Pr-Head-Sha: 89c830c8fe9c487e0dd14087dc99a720496d5c0f
GitOrigin-RevId: e73f51cf62e973d664cdfd8193b830e24e007a7c
Change-Id: I3066e87ed7cfa2bda19089979c722f1efe4103cf
M fragment/fragment/api/public_plus_experimental_current.txt
M fragment/fragment/api/restricted_current.txt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/strictmode/FragmentStrictModeTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
M fragment/fragment/src/main/java/androidx/fragment/app/strictmode/FragmentStrictMode.java
A fragment/fragment/src/main/java/androidx/fragment/app/strictmode/TargetFragmentUsageViolation.java
il...@google.com <il...@google.com> #3
FWIW, the reason this manifests as it does is that NavHostFragment creates its NavController in onCreate() and this bug caused onCreateView() and onViewCreated() to run before the Fragment was attached and created. This caused us to set a null NavController on the root View, which is why findNavController() is unable to find the NavController.
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 69f6a43d7d0e8ac2b7bd68e6f01a74ad45732b06
Author: Ian Lake <ilake@google.com>
Date: Thu Apr 04 13:05:44 2019
Fix method ordering when using @ContentView+<fragment>
When calling through to a @ContentView annotated
constructor of FragmentActivity (or AppCompatActivity),
Fragments created via <fragment> are inflated before
the FragmentManager is moved to the CREATED state.
By adding a check around ensureInflatedFragmentView(),
we can avoid cases where onCreateView() and onViewCreated()
are called before the Fragment is attached and created.
Test: ContentViewTest and updated Navigation testapp
Fixes: 129907905
Change-Id: I278beedacf8633f84bfc918246ac8caef894ab1e
M fragment/src/androidTest/AndroidManifest.xml
A fragment/src/androidTest/java/androidx/fragment/app/ContentViewTest.kt
M fragment/src/main/java/androidx/fragment/app/FragmentManagerImpl.java
M navigation/integration-tests/testapp/build.gradle
M navigation/integration-tests/testapp/src/main/java/androidx/navigation/testapp/NavigationActivity.kt
https://android-review.googlesource.com/940225
https://goto.google.com/android-sha1/69f6a43d7d0e8ac2b7bd68e6f01a74ad45732b06
Branch: androidx-master-dev
commit 69f6a43d7d0e8ac2b7bd68e6f01a74ad45732b06
Author: Ian Lake <ilake@google.com>
Date: Thu Apr 04 13:05:44 2019
Fix method ordering when using @ContentView+<fragment>
When calling through to a @ContentView annotated
constructor of FragmentActivity (or AppCompatActivity),
Fragments created via <fragment> are inflated before
the FragmentManager is moved to the CREATED state.
By adding a check around ensureInflatedFragmentView(),
we can avoid cases where onCreateView() and onViewCreated()
are called before the Fragment is attached and created.
Test: ContentViewTest and updated Navigation testapp
Fixes: 129907905
Change-Id: I278beedacf8633f84bfc918246ac8caef894ab1e
M fragment/src/androidTest/AndroidManifest.xml
A fragment/src/androidTest/java/androidx/fragment/app/ContentViewTest.kt
M fragment/src/main/java/androidx/fragment/app/FragmentManagerImpl.java
M navigation/integration-tests/testapp/build.gradle
M navigation/integration-tests/testapp/src/main/java/androidx/navigation/testapp/NavigationActivity.kt
sa...@gmail.com <sa...@gmail.com> #5
FWIW, the reason this manifests as it does is that NavHostFragment creates its NavController in onCreate() and this bug caused onCreateView() and onViewCreated() to run before the Fragment was attached and created. This https://trustanalytica.com/online/best-urgent-essay-writing-services
Description
Version used: 2.1.0-alpha02 (Navigation), 1.1.0-alpha04 (AppCompat)
Devices/Android versions reproduced on: Pixel 3 XL (API Q)
Using the new AppCompatActivity constructor that accepts a @LayoutRes contentLayoutId and then calling findNavController in onCreate throws the following IllegalArgumentException:
2019-04-04 21:42:06.096 23637-23637/com.example.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.debug, PID: 23637
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.debug/com.example.MainActivity}: java.lang.IllegalStateException: Activity com.example.MainActivity@a6fc922 does not have a NavController set on 2131362030
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3113)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3249)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:81)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1940)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:209)
at android.app.ActivityThread.main(ActivityThread.java:7046)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:486)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
Caused by: java.lang.IllegalStateException: Activity com.example.MainActivity@a6fc922 does not have a NavController set on 2131362030
at androidx.navigation.Navigation.findNavController(Navigation.java:61)
at androidx.navigation.ActivityKt.findNavController(Activity.kt:30)
at com.example.MainActivity.setupBottomNavigation(MainActivity.kt:49)
at com.example.MainActivity.onCreate(MainActivity.kt:44)
at android.app.Activity.performCreate(Activity.java:7658)
at android.app.Activity.performCreate(Activity.java:7647)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1295)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3088)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3249)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:81)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1940)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:209)
at android.app.ActivityThread.main(ActivityThread.java:7046)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:486)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
Using the traditional call to setContentView in onCreate before calling findNavController does not experience this crash.