问题
scenario :
MainActivity.kt
: activity_main.xml
contains my_nav_host_fragment
in mobile_navigation.xml
first_frag_dest is the startDestination and there is second_frag_dest also, with respective classes FirstFragment.kt
and SecondFragment.kt
.
I have setup bottom navigation for switch between two fragments using the Android Jetpack Navigation components.
When the Second Fragment is opened for the first time if FirbaseUser is null, A Welcome Activity is launched which is configured for GoogleSignInusing Firebase.
In WelcomeActivity.java
I have a function updateUI(user: FirebaseUser)
to update the UI.
Now, what code should I write in updateUI function such that I am redirected back to the Second Fragment.
Please tell how to do it using JetPack Navigation components.
Note: Principles of navigation say that only one activity must exist but here I am compelled to use an Activity for GoogleSignIn due to Firebase restrictions.
回答1:
If you want to close your WelcomeActivity
and return to the activity below it, have your updateUI
method call finish():
Call this when your activity is done and should be closed
来源:https://stackoverflow.com/questions/53854226/android-jetpack-navigation-how-to-open-a-fragment-from-an-activity-not-associa