How can I show two activities at a time in android - android

I have 2 activities, In first activity I have a button and I want when user clicks or move up that button the second activity come from bottom and stop when it goes to the half of the screen. I don't understand how can I achieve this. I also searched google but they show some type of dialog boxes :(.
This is what I want. When app start 1st activity is shown on the screen but when user click ^ this button both 2 activities show 50% on the screen.
Can anybody tell me how can I achieve this. Is it possible???

You would achieve this using Fragments.
I would suggest you start with the offical documentation - https://developer.android.com/training/basics/fragments/index.html

In order to create the interface above you could use fragments instead of activity.
In your case you need to have an activity with two fragments (you can use coordinatorlayout).
If you don't have enough knowledge about fragments I recommend to read those articles:
Codepath fragments guide
Vogella fragments guide

Convert Activity to Fragment and use <FrameLayout> on page to display/remove fragments from page.
Fragments are reusable components Refer to convert Activity to Fragment
This might help you understand how to work with Fragments link

You should read about fragments. They can be used for the UI you described. You can make it so that a second fragment is GONE, and when the user presses a button, it becomes visible. You should probably use a relative layout for the two fragments.

Related

should I use fragment or viewpager for my app

Demo1
Demo2
when users click the button to answer the questions for the TextView on the top, the TextView will change the questions depends on the user's answer.
(I think this part won't be hard for me)
But what should I do after user click the button, the buttons will change as well, please see the demo picture.
are there any skills I should study first? like framelayout?
Thank you for your answers.
It really depends on specific needs, but generally speaking, google guidelines are toward the use of fragments.
I'm developing Android apps since just few months and I'm using the single activity/multiple fragments approach. You have to learn how to use fragments, e.g. their lifecycle compared to the attached activity or how to handle events among fragments (EventBus can help you for such task).
You can find more discussions about this approach here
Cheers.
you can create a N fragement with your nuber Button and you set your buttons in this fragement (Demo 1)
but in click a one button you can replace a Specific Fragment (Demo 2) in your framelayout be placed in your Activity

It would be correct to use the NavigationDrawer to open Activities, not fragments?

My application basically has one main activity. Within it there are three tabs, each with a fragment. Something similar to the layout of whatsapp.
To add more functionality to the application, I saw that the NavigationDrawer would be a good option. But because of my application running with a main activity with children fragments, I wonder if it would be a bad practice loading activities and not fragments, when the User clicking on any item NavigationDrawer.
Or does the best meneira would turn my MainActivity in a fragment? It would give me a great job ..
I would like to suggestions =)
You can use the NavigationDrawer to open new activities. Basically just make each of the Activities have the same-looking Drawer and the user experience will be same as if you were replacing Fragments.
However, I would discourage this. I have been working with apps that mixed Fragments and Activities for the NavigationDrawer and the outcome was problematic, especially when it came to backtracking and saving state. It did work, but required hackfixing and some illogical code.
The best practice for the NavigationDrawer is to have one "container" activity which does little more that just exchanging Fragments in a FrameLayout it holds. The rest of the logic would be in the Fragments. This way the app is easily extendable and the backstack is handled by the platform.
I prefer Fragments but there is no problem to open new Activities. Instagram does something similar. It has tabs (I know that you want to use NavigationDrawer, but this is just a example), and one on these tabs open a new Activity, with the X button to close the Activity.
Instagram Main Activity:
New Activity with close button:
The Series Guide Android application does exactly the same. It opens Activities from the Navigation Drawer. Such Activities extend the BaseNavDrawerActivity. The Activity's start and exit animations are custom to make the transition looking smoother.
I would recommend this approach since it's much more easier to manage Activities' back stack than Fragments'.
Proceed happily with opening activity as well. Make sure you put the back button on the opened activity so that user would have clear idea that which screen is the primary.
But wait..
If you are worried about whether you are following the standards (industry) or not then read below:
If all your activity has the equal importance for users (including the tabbed one) then recommended way is to use the fragments and on the other side if you don't want people to get distracted by navigation drawer icon or tabs then better to open a new activity with just a back button on top..
I hope it would give you idea how to proceed..

Fragment or Activity?

Hi all android noob here.
One of the difficulties I have in android is choosing what to load should I load the fragment or should I fire an activity?
My module will from a recyclerview, once user clicks on the item it will take them to another screen which contains a viewpager with two tabs news and topics.
for this account, should I load it via fragment or should I start another activity?
Additional question:
in what terms should I start an activity?
in what terms should I use fragment for hoping on the next screen?
Thanks.
First of all see the follwing official documentation: Navigating between sibling screens
There are no ideas about what should you use activity or fragment, but if you open a fragment you have to use buttons "Up" and "Back" and then you press them you should go back to the previous activity at the same state. So if you use the fragment you have to override a lot of code for appropriate working code, so in my opinion it's better way to start new activity.

How to use Fragments

I'm trying to wrap my head around when exactly I should use Fragments and if I'm going to use them how to do so properly.
To my understanding Fragments should be used if you want a more flexible UI as it will be easier when rotating the device and easier to have your layout work with multiple screen sizes.
It seems to me that it is good to use them because you could have an app with ONE activity and multiple Fragments so the activity will be able to get calls from callbacks while the Fragments change what the user is seeing and interacting with. If I were to compare two apps, one made with Activities and the other with Fragments I would imagine to see something like this:
Activity app has a log in screen. The user can log in and it brings them to the main menu (New Activity). Once there they select the Friend button which brings them to a new Friend activity.
Fragment app has an Activity that loads the Log in Fragment into it's FrameLayout. The Log in Fragment allows the user to log into their account. Once it logged in, it replaces the Log in Fragment in the FrameLayout with the Main Menu Fragment. User presses Friend button, it opens the new Friend Fragment in the Activities FrameLayout. In this case all the work is being done in the Fragments but the Activity is just really holding them.
Please tell me why this is the incorrect use... or why this is correct.
Cheers
Take a look at the official Fragments doc. Short answer: always use Fragments. Fragments are better for reusability, flexibility, etc., etc.

Display part on another Activity (or Fragment?) Android

I have to deal with two ActionBar displayed at the same time on the screen. There's an onClickListener on the second one which allows the second activity to be shown on the entire screen after a click, with an animation.
I have no idea how to do that. Two activies, fragments? ViewPager? ... Absolutely no idea. Could you please help me? Thank you.
EDIT : here is a picture of what I wanna achieve http://romainpellerin.eu/so_android.png
You have to see it in order to clearly understand my problem.
Definitely Fragments.
When you bring in the second fragment specify animations in the fragment transaction before you commit it.
There are tons of tutorials online. Here some more help.
Android Fragments and animation
SDK
http://developer.android.com/guide/components/fragments.html
how to make fragments backwards compatible
http://developer.android.com/training/basics/fragments/support-lib.html

Categories

Resources