I am creating new android application using android architecture components.
Here the scenario is,
I have created one ( no other activities ) main activity where I have put NavHostFragment along with drawerlayout. Now I have fragment for splashscreen, where I made toolbar hidden, and everything works fine.
Now, when after 5 seconds I call other fragment using navigationcontroller, in new fragment(home fragment), instead of showing icon to open drawer, it shows back button there. And on click of back button icon, it loads splashscreen again.
Any suggestions ?
This happens because the navigation graph adds fragments to backstack and when you press the back button that pops backstack and navigates to previously fragment.
I suggest you use an activity as the splash screen for better control your stack and backstack and make it as the launcher and finish it after 5 seconds then start the main activity.
Take a look Principles of Navigation
Related
My problem is illustrated by this screen record.
When I click the FAB on FinanceFragment, it will open AddTransactionFragment. But when I navigate to ReminderFragment and go back to FinanceFragment, the AddTransactionFragment is destroyed.
How could I -- similar to the YouTube app when one switches between fragments -- keep AddTransactionFragment visible while I navigate to another fragment?
I tried to add addToBackStack() but this turned out not to be what I was looking for.
I wanna make an application that has multiple screens (screen1, screen2, and screen3), and for navigating between screens I wanna use bottom navigation bar. I wanna make it like Instagram app that can navigate back to the previous screen when the back button is pressed. I have made an app with navbar but when I press the back button the application is closed directly even after I navigate to other screen.
Override the onBackPressed() method of your activity, and write back button logic on it.
I am currently trying to use the Android Navigation component to navigate from one fragment (A) to another (B) by animating fragment B up from the bottom of the screen (over fragment A) and subsequently animating fragment B back down when the back button is pressed. I currently have an action defined for this:
<action
android:id="#+id/action_landingFragment_to_bookingFragment"
app:destination="#id/bookingFragment"
app:enterAnim="#anim/booking_screen_in"
app:exitAnim="#anim/nothing"
app:popEnterAnim="#anim/nothing"
app:popExitAnim="#anim/booking_screen_out"
app:popUpTo="#id/landingFragment" />
However, when I navigate to fragment B from fragment A currently, I get a nice smooth slide up from the bottom of the screen, hit the back button and see fragment B disappear instantly to display fragment A again, with no animation. I currently use no custom code for the back button on fragment B (though I tried navigateUp() and popBackStack() in an OnBackPressedCallback to see if I was missing something regarding these. I also wonder if there is an issue with Z-axis of the fragments (similar to this thread) but my normal enter/exit animations work fine and I have tried a more traditional set of animations (slide left/right) in which the enter and exit animations play but the pop animations once again do not.
Can anyone suggest the correct way to do back navigation such that these pop animations should be visible?
I'm a beguinner with Android programming, and in my app I have a Bottom Navigation View with 3 fragments.
One of those fragments has a button that allows the user to open another Activity to listen to music. But whenever the Activity is opened using Intents, the Bottom Navigation View from the previous screens disappears.
Can I open an Activity from a Fragment, but still have the Bottom Navigation View active?
Below is attached a link with an image of the mock-up I've made, hope it helps to clarify the question:
Thank you in advance for trying to help me out!
Reason
Well I guess (because I have no clue about your code base) the bottom navigation bar is a part of the main activity in which the fragments are being contained. When you are starting a new activity, the main activity with the bottom navigation goes as the music player layout loads.
Recommended Solution
Instead of keeping the music player as an activity make it a fragment and load in the view you are using as the fragment container in the main activity.
Another Way round (Not recommended)
Make another view of the bottom navigation bar in the music player activity and map the actions of the button click to load the main activity.
It might be a bit time taking and buggy initially but with debugging and testing, you can make it work.
But again its not a good option.
I'm testing the new Navigation Component and I have some "problems" about how it work in some cases.
I make this app https://github.com/LipeDuoli/navPlayground to test
I created the login activity (with will have several fragments) has no toolbar or bottom navigation. When I finish the login I want to go to main Activity (has toolbar and bottom navigation).
How I can remove the login activity from the back stack, to not return to login when press back? I tried to select the popTo option on navigator editor but had no success
From the main activity I want to show a detail from an item. When I execute the action to navigate to the next fragment, how I can hide the bottom navigation only on this detail fragment?
thx
You could make MainActivity your opening activity. Then start the LoginActivity from
startActivityForResult(intentObj)
setup some condition to check if the device is already logged in MainActivity and if it doesn't accept the condition start the LoginActivity.
Another way would be to call finish() in login activity