In my requirements i need to add multiple nested fragments as am using navigation drawer as a main navigation so am using nested fragments like lets say Fragment a->b->c->d-> like that i have created is that a right way to do with using multiple fragments like would cost anything for application ? As beginner am very confused what to do with is it a bad practice i may be dumb question ! any solution you people are here to help beginner like us thanks in advance!
This is not a bad practice, but mostly we should keep fragments in Activity, instead nesting them which is complex but sometimes, it also depends on design of apps, which we must have to follow either by nested fragments or whatever.
In case of Navigation Drawer, you can be enough by adding fragment to navigation list items click and then start activity on fragment click.
Fragments are very useful.
An Activty can have multiple fragments ,and fragments cannot have fragments inside them.
In Android 4.2 there was support for Nested Fragments Where you can use fragment inside other fragment. But your fragment must be dynamic.
Thanks
Related
Is it possible to create an activity slide in and slide out transition without animating the whole activity? Similar to fragment transition but with activities.
I know this could easily be done with fragments but I would like to avoid handling multiple fragments in a single activity to avoid creating a God Activity.
What are your thoughts on this?
As we have discussed in the comments, using Child Fragments could be an idea to solve the issue.
I have made a swipe tabs using fragments. But is possible to use activities instead of fragments? For example. I have 3 swipetabs, "View","Add","Delete" and 3 seperate activities for each on of these functions. Is there a way that if a swap from "View" to "Add", it takes me to the "Add" activity, an so on.
As i don't have enough reputation i cannot comment on this so am answering. Instead of using activity try to use fragment as google suggests you can do everything in fragments same as you can do in activity infact you can do more thing in fragments so i recommend you to use fragments so please take a look at communication between two fragments https://developer.android.com/training/basics/fragments/communicating.html
I have a NavigationView used as a slide-in menu. Each of that menu items is a use case itself, therefore I tend to using activities containing different fragments.
But nearly every example of NavigationView/NavigationDrawer uses fragments, so I don't know what to use here.
I thought different use cases should be "encapsulated" in own activities, therefore I don't really understand why Navigation[View/Drawer] uses fragments. And that leads me to my question: for a Navigation[View/Drawer] containing completely separate use cases - should I link to activities or fragments?
I posted a similar question
I have created around 4-5 apps with mid-big size project. I used Fragments for Navigation Menu clicks and had to manage lots of Lifecycle events and Memory Leaks and shit stuff. The Performance degrades and app becomes slow.
Then in one of the app I Used Activities for each Navigation menu clicks, treating it separate Entity/Module. This Activity would then use fragments if they had child views.
Doing so I had a great app, less trouble and I could concentrate on Business Logic rather than maintaining fragments.
Although Google recommends Fragments, But I never liked them, they always put me in trouble and handling them is a mess.
In my current Project I have created a BaseActivity implementing Navigation and all the other Activity extend it.
the NavigationDrawer and the contents are all just Views inside the Activity view hierarchy.
The use it of fragments is usually shown in tutorials because you can encapsulate each item inside a fragment, and fragments is the usual Google advice, even though they're a pain in the ass and have horrible drawbacks regarding animation.
But the direct answer to your question is: It's all just a matter of structure and organisation and it really does not matter how you do it, because in the end they're all just views in the Activity view hierarchy.
You can "manually" inflate views and put in the content area.
You use fragments to separate the views and logic and their own container.
You can use activities with different content and the same NavigationDrawer.
I am developping an app with an activity which switches between a few fragments. I was wondering if it is possible to have one of this fragment with tabs in the action bar, but not the other ones, knowing that, in general, the activity is tabbed and the tabs switch between fragments.
In a nutshell, I want an activity with a few fragments, and one of this fragments should have tabs to browse between other fragments, is that possible?
Ofcourse it is possible, take a look around StackOverflow, there are a couple of questions already.
Instead of normal TabHost your should use FragmentTabHost and because you will have fragments inside a fragment, you will have to use getChildFragmentManager() instead of getFragmentManager().
Adding tab inside fragment
Nice post Marko! I was just typing up basically the same answer. Here is a link for the documentation on Nested Fragments hope that helps as well
I'm trying to create a layout that has a stationary footer with activities that slide behind it. I've been told to use Fragments, but that would mean that I would have to convert my already existing Activities to Fragments - right? Here is a diagram of what I'm trying to achieve: http://i.imgur.com/K8Iao.jpg
What I think #TarunMaheshwari is trying to say is that instead of having 3 activities (eg. classes with extends activity), replace it with extends fragment (obviously there are other minor changes you might have to make for the code to work) and then create a main activity (with extends FragmentActivity) that has the static footer you want which can call on the 3 different fragments.
Recommended readings:
http://developer.android.com/guide/topics/fundamentals/fragments.html
http://android-developers.blogspot.ca/2011/02/android-30-fragments-api.html
I believe using fragments is the right solution for your app. However, from what I understand from your question and comments, you really want to avoid using them. To use activities instead of fragments, implement a Tab Layout with a Tab Host and Tab Widget as explained in this tutorial. This solution allows you to use the tabs to switch between activities.
To align the Tab Host to the bottom of the screen, have a look at this tutorial.