Android: Why shouldn't I use activities inside tabs? - android

I've read at a few places that I should not be using Activities as contents of my tabs. I would like to know why this is not a recommended approach... Any suggestions?

I'd flip it around: why would you want to use activities as tabs? All you do is add overhead and complexity. Just use Views for the tabs.
If you have something that just has to be both a tab and a separate standalone activity, reuse the View.

Related

Stacking up android widgets/views in one layout file?

Is it advisable to stack up multiple views and depending on the preceding activity, show the appropriate widgets/views to user? e.g. To have 2 or 3 forms in 1 layout file(xml),and show one view depending on what the user wants to see.
you can use Fragments... Add the right fragment to activity based on the preceding activity.
Fragments do this. Stacked views are nice for collapsed elements. There are uses for them as well. The choice is based on your particular use case. From what you've said, I would recommend Fragments.
The nice thing about fragments is that they handle life cycle events (like activities) but without the need for serializing and parceling data to communicate among your fragments.
As for your question "Is it advisable to layer views?" I would advise against layering different forms UI. The xml design and maintenance can grow hair real quick.
Fragment is the solution in android when you want to show some specific layout to the user create 2,3 fragments android depending on the condition load the appropriate fragment.
You can go through this to get started on fragments.
https://developer.android.com/guide/components/fragments.html

How can I add multiple activity to the same screen in android

I want to divide my screen into four parts and add activities in each part. I am not interested in using fragment. Each activity should behave independent of other. Attached photo is showing what I exactly want to do.
In each child activity I want to add VideoView or WebView depending on the selection from menu item.
How can I do it. I didn't find any way to add activity to an activity.
Thanks :)
PS: Activity means Activity not fragment.
i strongly recommend 'using fragments' in your case as ActivityGroup is deprecated in API 13..
The only way you can do it by using fragments. Here is the simple example on how to add multiple fragments on single activity Link
Edit link
You can achieve this design by using four fragments, one for each child view inside a single activity.
The recommended way is to create a single XML layout for your activity, and create four fragments inside that layout.

Best way to add tabs within android app

I'm thinking of adding tabs to my android app. Currently, I am using the same activity and adding the appropriate fragments based on the tabs selected. I was wondering if that's a good way, or should I add an activity per tab and then within the individual activity, have fragments as needed?
I think you are on right track. Have one Fragment Activity and attach all the fragments to that activity.

Using Fragments to switch activities

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.

Anyone have example code using switched Views instead of Activities inside a TabHost on Android?

The Android developer guide (http://developer.android.com/resources/tutorials/views/hello-tabwidget.html) states:
`You can implement your tab content in one of two ways: use the tabs to swap Views within the same Activity, or use the tabs to change between entirely separate activities. Which method you want for your application will depend on your demands, but if each tab provides a distinct user activity, then it probably makes sense to use a separate Activity for each tab, so that you can better manage the application in discrete groups, rather than one massive application and layout.
In this tutorial, you'll create a tabbed UI that uses a separate Activity for each tab.`
In my cases, it doesn't make sense to have separate activities for the tabs so I want to switch views, but it would be nice to see an example.
Gee, thanks Google!
In my cases, it doesn't make sense to have separate activities for the tabs
I have yet to find a good argument for having separate activities for the tabs.
so I want to switch views, but it would be nice to see an example.
Here is one. Here is another.
The recipe is pretty simple:
Step #1: Add the tab contents as child Views of the FrameLayout
Step #2: Use the setContent() (on TabHost.TabSpec) that takes an ID as a parameter
Step #3: There is no step #3

Categories

Resources