How can I add multiple activity to the same screen in android - 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.

Related

How can I show two activities on the same screen?

I am trying to find a way to show two activities on the same screen, I have two activities main and content activity, the main activity has a mini-player that's implemented and only works in an activity and the content activity has some implementations that also only work in an activity so the solution of converting them into a fragment does not work for me. I need to find a way to show the mini-player in the main activity inside of the content activity. I have looked online and none of the solutions so far have been working for me!
You have 2 ways to complete task.
Fragments, They can do same things as activity. Its lite weight activity class with more flexible to attach and detach from the screen.
Views, If you think your task can be done by only activity then use views for it. you can apply different animations and show/hide feature to display content on the screen within single activity.
Fragment is a part of an activity, which contributes its own UI to that activity. Fragment can be thought like a sub activity. Where as the complete screen with which user interacts is called as activity. An activity can contain multiple fragments.Fragments are mostly a sub part of an activity.
From document
For example, a news application can use one fragment to show a list of
articles on the left and another fragment to display an article on the
right—both fragments appear in one activity, side by side, and each
fragment has its own set of lifecycle callback methods and handle
their own user input events. Thus, instead of using one activity to
select an article and another activity to read the article, the user
can select an article and read it all within the same activity
Use Fragment.Fragment are Runs inside the Activity.
you can display multiple fragment in same time.
Refer Fragments
Create a fragment
At first, Android system can show only one activity on the screen.
You should not use Activity.
Please use Fragment. You can use multiple fragment on the same screen.

How to select the activity and the fragment

What scenarios using fragments what scenario using the activity , How can I make sure you when to use the activity when using fragments !
Basically, when you want a fixed portion of the screen and the rest will be changing, you want to use fragments.
If all your app is going to be on different screens, you want to use Activities.
Anyway, at least you will need one activity to hold your fragments.
Hope this helps.
As i know,You need to extend the fragment when you are displaying the view into tabs.
Otherwise you can extend activity.
It depends on your requirement. if u want to expose your toolbar throughout your application you can use fragment both activity and fragment are quite similar . You can also use only one activity remaining things may be your fragment
It depends on UI which you are creating.
If you are creating Multi-Pane UI then you should use Fragment.
And if you are creating some part of screen which can be reused then for that part you should create Fragment as Fragment is meant for re-usability.
If you are creating stand-alone screen then you should use Activity
For more info please refer this link How to choose Activity or Fragment if both scenarios are possible?

Why should I not add Fragments to the activity layout XML file?

Edit: source : http://developer.android.com/training/basics/fragments/creating.html last parargraph says :
Note: When you add a fragment to an activity layout by defining the
fragment in the layout XML file, you cannot remove the fragment at
runtime. If you plan to swap your fragments in and out during user
interaction, you must add the fragment to the activity when the
activity first starts, as shown in the next lesson.
Thanks in advance.
You can use fragments in two ways ,
Static Fragments
Here you can define the fragment in whatever the layout file you need. Only thing is, that defined fragment can not be change at the run time. So, re-usability will be issue here, you cant take the advantage of the re-usability of fragments in this case.
Dynamic Fragments
Here you can define a place holder(frame layout etc) on your layout and you can add/replace whatever the fragment you expect at any time while your activity is running. This ensure the re-usability.
Also you can use backStack if back navigation is required.
So, it depend on your requirement.
If the fragments are defined in Xml you won't be able to change them at runtime; in that case I'd suggest using an <include layout="#layout/my_inner_layout"/> tag, that is not only better performance-wise as it is easier to use (you can access the views defined in my_inner_layout.xml using findViewById() method from the host activity).

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.

Keep footer for multiple activities

I'm creating an app which requires the footer to remain constant among various activities. That is, when animating to another activity, the footer doesn't animate with it - it stays there. Here is an example of what I mean: http://www.youtube.com/watch?v=EwXjdTvVXHQ&feature=related
I know it's an awesome app, but please don't forget my question ;)
Use Fragments to switch out your content, then you can keep one activity with the same footer. Fragments are backported all the way to Donut.
Use only one activity with footer and body in your app, switches and animates body only just like switches in activities.
Create a dummy class that extends an Activity and add footer to it.using xml (or the sameway you would do for other activity).
And extend this class in your app wherever you want footer.

Categories

Resources