I have an app which contain three tab with three fragment mainly A,B,C lets suppose I am on tab 2 which contain fragment B when app goes in background and again resume then fragment A is showing instead of fragment B. Ho do I resolve that?
Related
Suppose I have different fragments within an activity in backstack such as [1]->[2]->[3]->[4]->[5] with Fragment 5 presently visible on the screen. Now I want to go to Fragment 2 without destroying Fragments 3 and 4 on a single press of a button. How can this be done?
I have a question. Refer to this:
How to manage multiple Activity stacks in an Android app, like you would on iOS with multiple UINavigationControllers within a UITabBarController?
With this visualization:
From the image above:
I have 4 tabs with button view
Tab 1 pressed, activity appears. Go to another sub activities, then tab 3 pressed.
When tab 3 pressed, activity appears, then tab 1 pressed should resume previous sub activities.
Then my problem is :
When tab 1 is pressed, i always start activity without the previous sub activities within it.
Then how can I resume activity contains sub activities that already in stack?
You should use fragments here inside tabs. Fragments stack are easy to manageable and lightweight process.
I am currently having a mainactivity which holds another five activities in a listview. Upon clicking it will open the corresponding activities.
I actually want to use tabs with viewpager.
Now, Do I need to start my activities when clicking on each tabs
or I have to keep one activity and pass only the fragment to the
viewpager?
I have to implement navigation structure like iOS or you can say like browser. where in my application it is like i have 3 tabs and for each tab there is flow of multiple fragments like
Tab 1 --> Fragment 1--> Fragment 2--> Fragment 3
Tab 2 --> Fragment 1--> Fragment 2
Tab 3 --> Fragment 1--> Fragment 2--> Fragment 3--> Fragment 4
And navigation is like when user switches tab then can view last opened Fragment of that Tab and on pressing Back should go back to previously opened Fragment of that Tab. All these Fragments load from single Fragment Activity so what I'm thinking is to manage Navigation manually by creating three different stacks keeping track of opened Fragments in those Tabs.
What i want is a method by which i can bring previously added fragment to front without pop of any other even there are some which added after that fragment. And on back press I'll pop the current fragment and bring in front another previously added fragment according to my own managed stacks.
I searched for method to bring in front previously loaded fragment by tag but they will pop all the fragments loaded after that fragment which is not acceptable for me.
You can try
getSupportFragmentManager().beginTransaction().attach(fragmentA).commit;
or
getSupportFragmentManager().beginTransaction().show(fragmentA).commit;
and hide other fragments you have in your FragmentActivity by looping through all given by
getSupportFragmentManager().getFragments();
//This gives list of fragment in stack
I'd like to show a different fragment in a TabHost, for every tab. But
it seems that there's no easy way to do this. TabHost can only accept
A. Views or B. Intents that launch Activities when the user selects a
tab.
Going with A means that I have to initialize every fragment and load
them into container Views that are given to the TabHost. But I want
these fragments to load only when needed - when the user selects their
tab that is.
Going with B means that I load the fragments into separate Activities
for each tab. But I'd like the fragment to be able to reach the
"original" parent Activity, not just some shell Activity that hosts
them in a tab content.
Am I missing something? Is there a way to manage fragments with
TabHost properly?
Some hits here:
fragment Support with Tabhost
Android 1.6 & Fragment & Tabhost
For what I understood, "link" a fragment inside a TabHost isn't allowed, you need to create activities that include your fragments and then call these activities from TabHost.
EDIT
the "official solution" from Google, and with nice animations.