Back Stack in fragments using Tabs in Action Bar in Android - android-layout

I am developing an application which have following requirements:
1) App has few tabs and each tab has multiple activities.
2) There should be proper back navigation to make the application user friendly.
For this, I used action bar and tabs in my application.
Tabs has multiple screens (Requirement).
Tab 1: Fragment A --> Fragment B ---> Fragment C
Tab 2: Fragment P --> Fragment Q ---> Fragment R
Tab 3: Fragment X --> Fragment Y ---> Fragment Z
Now I want to use the back functionality from each fragment So the user comeback from next fragment to previous fragment in each tab like:
Fragment c --> Fragment B ---> Fragment A
I want that user can use back button of device and We can use custom button in action bar for the back navigation.
I also want to change the title of action bar according to the current fragment.
How can I implement this? Any other better approach which can be used in this situation.'
Please reply. I am not getting solution for this type of situations.
Thanks a lot.
Please provide me solution or best approach for this. Thanks Again.

Have a look at this example, it should do what you want.
https://gist.github.com/andreynovikov/4619215

Related

Jetpack Nav-Graph navigation to current fragment itself also having it in stack

Fragment Structure
Fragment Stack I want so that on back press I load fragment with my old data state
A->B->C->C
Fragment Stack, nav graph created even if I move from C to C again. (that is what I judge while implementing)
A->B->C
I want to go to C itself many times and then also on back press
getting all loaded C fragments with the old state it has.

Switch from fragment to activity in android studio

I made an application where I integrated the tabbed activity. In the tabbed activity I put 3 fragments. Now in the 3rd fragment I put a button and I want when I click on the button it redirects me to a new activity I did. I used an intent as we usually do between activities but it doesn't work. Need help please
use getContext instade of Activity.this. use the below code in your button to redirect from fragment to activity
yourButton.setOnClickListener(view -> {
startActivity(new Intent(getContext(), Your_Activity.class));
});
If the problem is not solved yet, let me know with logcat error.

moving from fragment to bottomNavitem, Onclick of that bottomNavitem, it opens that fragment again i need to open start fragment again,without delay?

i tried to open bottomNavitem from fragment with this code on ,it opens bottomnavitem ,on comming back same bottomnavitem it open same fragement while i need to open starting fragment ,using popbackstack removes but it shoes delay bad ui
AppPreference.lastSelectedCoinName = it.replace("/", "")
// findNavController().popBackStack()
(activity as HomeActivity).changeBottomNavItem(2)
Are you using Android Navigation i think it would solve your issue

flip the whole layout onclick button then show another activity

I have many buttons on my activity and I need to flip the whole layout once a single button was clicked.The button that was clicked must show a specific activity which is clickable also with flip.
Help me here...
Note: I've seen a lot of tutorials online but they only flip the single image. thanks
A flip activity is basically a rotation at Y axis. You can achieve it via ObjectAnimator.
ObjectAnimator anim=ObjectAnimator.ofFloat(yourView, "rotationY", 360);
In case you work with API Level below 11 you need to use Nine-old-androids library since new Animation API which includes ObjectAnimator, ValueAnimator and a couple more became available with API Level 11 and above.
Refer to the lib;
http://nineoldandroids.com/

possible spotify programmatic navigation bug?

Possible bug description
following on from this question I think there is a bug in the Integrating with the Spotify Application’s History if I create tabs A, B, C where A contains a list D.
If I click A --> B --> C --> A
this could be done programmatically as
spotify:app:appname:A
spotify:app:appname:B
spotify:app:appname:C
spotify:app:appname:A
which works fine. However if I click
A --> A:D --> C --> A --> B
this could be done programmatically as
spotify:app:appname:A
spotify:app:appname:A:D
spotify:app:appname:C
spotify:app:appname:A
spotify:app:appname:B
Which allows me to click back on A if I am viewing A:D (solving the problem of my original post)
However when I click through the second sequence and view the state of sp.core.getArguments();
the second sequence shows up as
spotify:app:appname:A
spotify:app:appname:A:D
spotify:app:appname:C
spotify:app:appname:A:D
spotify:app:appname:B
Implication 1
If I use the state and creating the display with something like
sp.core.addEventListener("argumentsChanged", tabUpdate);
function tabUpdate(po) {
var args = sp.core.getArguments();
switch(args[0])
{
case "A":
showA(args);
break;
case "B":
showB();
break;
case "C":
showC();
break;
}
it would display incorrectly as the :D is attached to the tab A when I just click on tab A.
Implication 2
If I just use the state so that the browse sees A and A:D as different (aka I can get back to A from A:D by clicking on the tab)
Fixing the display changes with an onclick element for the list D that would mean that it works clicking forward. However using the navigation buttons to go backwards will show up incorrectly. Ie if I click through then use the back button it will display
B --> A --> C --> A --> A
instead of
B --> A --> C --> A:D --> A
Alternative 2
with the same setup described above but using the reference to D on its own.
spotify:app:appname:A
spotify:app:appname:D
spotify:app:appname:C
spotify:app:appname:A
shows up as
spotify:app:appname:A
spotify:app:appname:D:A
spotify:app:appname:C
spotify:app:appname:D:A
Which means that when I click back to A from C it doesnt display A.
Question
Is there a way to get around this?
I can put together an app to replicate this if required.
I know what you're talking about and I can confirm that this problem exists.
Put simply, if you're on tab A, and you navigate inside that tab pushing to window.location, when you go to tab B and you click back on tab A, you get the same arguments which you got the last time you looked at tab A.
I think this actually makes sense because it maintains state history on each tab, BUT there are cases where you don't want this to happen, depending on your app's workflow.
One could use the argumentsChanged event handler to check for this but there is a problem: you can't tell whether argumentsChanged has been fired by clicking on a tab or by pushing the back/forward buttons.
If the event object passed to the argumentsChanged event handler could inform whether the user has clicked a tab or is navigating using back/forward buttons, then a developer could very easily solve these workflows.

Resources