Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
This turns out to be an issue with Fragments when specifically using:
- the ContentView annotated constructor
- a Fragment in XML
Due to the timing between dispatching onCreate() to Fragments and when setContentView() is called. We'll fix on the Fragment side and verify at both the Fragment and Navigation levels.
- the ContentView annotated constructor
- a Fragment in XML
Due to the timing between dispatching onCreate() to Fragments and when setContentView() is called. We'll fix on the Fragment side and verify at both the Fragment and Navigation levels.
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.