Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: using ActivityGroup to embed activities

Im in the conceptualizing/design phase of building an app and i've hit a bit of a snag. Essentially i was looking for a way to embed one activity into the UI of another similar to how a TabHost/TabActivity. There would be a window at the top of the screen which would contain the other activity, and below that would be buttons and controls that are independent of the above activity and should always be visible. The user would be able to navigate from one activity to another in the window without causing any change to the below controls.

While looking into the issue i ran across ActivityGroup, which looked like it would be useful, but how would i implement it? Anyone have experience with ActivityGroup or have another idea?

like image 880
mtmurdock Avatar asked Jul 16 '10 13:07

mtmurdock


People also ask

Can Android application have activity without layout?

The answer is yes it's possible. Activities don't have to have a UI. It's mentioned in the documentation, e.g.: An activity is a single, focused thing that the user can do.

What is an embedded Activity?

Activity embedding optimizes apps on large screen devices by splitting an application's task window between two activities or two instances of the same activity. Figure 1. Settings app with activities side by side.

What is activity tag android?

<activity> activity is the subelement of application and represents an activity that must be defined in the AndroidManifest. xml file. It has many attributes such as label, name, theme, launchMode etc. android:label represents a label i.e. displayed on the screen.


1 Answers

Yes, you'd implement an ActivityGroup, which will be the container of your other Activities. When the user clicks one of the buttons, you'd get a reference to the LocalActivityManager, and use it to start, and embed the inner activity. Something like this:

LocalActivityManager mgr = getLocalActivityManager();

Intent i = new Intent(this, SomeActivity.class);

Window w = mgr.startActivity("unique_per_activity_string", i);
View wd = w != null ? w.getDecorView() : null;

if(wd != null) {
    mSomeContainer.addView(wd);
}

Note, using this method can be pretty complicated, because unless the focus is just right, pressing the hardware buttons (like the menu button) will only only trigger events on the ActivityGroup instead of the inner Activity. You have to find some way to focus the inner activity after you add it to the container view, at which point the even will happen in the inner activity and propagate to the container activity.

It can be done, I've done it... and it works. It's just a bit more complicated than I think it should be.

Anyway, I got most of this information by looking at the TabHost code, which can be found here

like image 126
synic Avatar answered Oct 04 '22 21:10

synic