Using fragments as activities in viewpager - android

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?

Related

How to add a fragment and an activity in a viewpager so that the fragment appears on swipe?

I want the activity to be on the screen and a fragment to appear on swipe. Can I use viewpager? Viewpagers are generally used for multiple fragments. Can an activity and fragment be added in the viewpager?
Yes you can use viewpager, but, you cant put an activity inside a viewpager. only fragments. Its fairly easy to convert an activity to a fragment. With this you may now construct your activity in this heirarchy:
Activity
-ViewPager
--List of Fragments

How to manage fragment lifecyle in tab in android?

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?

What are the advantages of using Navigation Drawer with Activities VS with Fragments?

I want to implement a Navigation Drawer in my app but I am conflicted on whether I should use it with Fragments or with Activities (see image below for more details).
Is there any real advantages or disadvantages between the two or is it just a matter of preference?
Edit:
Just to clarify my question:
In the case of using Activities instead of Fragments;
When I select "Import" that will open an Activity and not a Fragment and if I select "Gallery" it will open an Activity with contents for gallery item etc. and so on for the other items in the Drawer window.
In the case of using Fragments instead of Activities;
If I choose from any of the Items in the Drawer window it will open their contents in Fragments for each Item selected instead of starting new Activities for each selction.
Remember Fragments need an Activity. You always have one minimum when using Fragments.
If you are talking about to use like main element in the most cases is best use fragments because you have more flexibility UI.
The performance would be better if you have 3 activities and 10 Fragments or have 13 Activities? Think about it, the navigation within the App would be the big challenge but it's just about using the right flow in your application.
Edit:
For instance:
Drawer With Activities instead of Fragments
If you were to use NavigationDrawer without Fragments then it would be best to keep the NavigationDrawer instance in a single Activity and when you navigate the app by choosing from the items in the NavigationDrawer then each of those Activities that are started should not implement the NavigationDrawer but instead should implement the back button to Navigate back to the "Main"/single Activity that the NavigationDrawer was implemented in.
Note: If you do want to implement the NavigationDrawer in multiple Activities you would have to recreate a new instance of the NavigationDrawer in every Activity that you desire to display it.
I suppose this would be a disadvantage vs using Fragments whereas if you used a fragment you wouldn't need many instances of the drawer you would only need one.
Drawer With Fragments instead of Activities
If you use the NavigationDrawer with Fragments then the drawer should be implemented in a single Activity and when each drawer item is selected, their contents are displayed in each of their very own Fragments(which is called inside of the central Activity which manages all the Fragment instances)

Launching fragments by sliding the screen from right to left in an Android application

I have multiple fragments in an activity. How do i load the next fragment when i slide from right to left?
I have made the fragment classes and also designed their layouts.
I have a main activity from which after login the user reaches next activity. This activity has multiple fragments. The first fragment is launched automatically but next fragments will be launched when user slides the screen from right to left.
You can use ViewPager to display fragments on swipe.
For Reference
How to implement a ViewPager with different Fragments / Layouts

fragment inside a fragment in android

In my application I am making use of navigation drawer which is in the MainActivity and this navigation drawer has say 5 fragments. I am not maintaining any backstack of these fragments.
Now, the first fragment has one button which when clicked pushes a fragment (which I call an inner fragment). Here, I am maintaining a backstack because I want to get back to the first fragment from the inner fragment.
Now, I have a requirement in which I want to navigate from an activityA to the inner fragment.
Is this possible?
One way that I have thought of is to have the push code inside the first fragments create method (and make this conditional).
But I don't think its an appropriate way. Any suggestions would be helpful.

Categories

Resources