Reputation: 31
I am hoping to save some time with a project and wonder if this is possible to do.
Currently there are some android phone screens that have already been developed by a former colleague. I am developing a new screen for a tablet that needs to have the content of an existing screen that he developed appear as a sub-screen (say a little box in the bottom right corner of the screen. This is aesthetically ok because the existing screen is small (phone). The screen I am developing is for a 10.1" tablet, so it only takes up a tiny portion of my screen.
However, the problem is that he had the screen all coded up in a nicely and integrated with an associated Activity. I am hoping to just reuse it by calling an Intent from my screen/activity unit, modifying it as little as possible.
QUESTION: Is it possible to have an activity appear as a subscreen of another activity? Mind you I know that you can launch a fire and forget activity from one screen with an Intent + startActivity(). But that will only take the new screen appear on top of the old screen.
Where as I want the new screen to appear as a subscreen of the existing screen. Any idea?
All pointers and recommendations are appreciated. TIA
Upvotes: 1
Views: 443
Reputation: 58361
You're looking for Fragments!
From the Android documentation:
A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running.
If you're developing for devices running Android versions prior to 3.0, take a look at the compatibility library, which allows the use of Fragments in versions 1.6 onwards.
Further, if you're developing for phones and tablets, you can reuse the same Fragment in both interfaces.
Upvotes: 4