views:

382

answers:

2

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?

+4  A: 

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

synic
oh great i was looking for the tabhost source code. this looks good, but its all very new to me. care to give some explanation of what you're doing in your code example?
mtmurdock
the startActivity part just starts the Activity without showing it onscreen. Then you get the View that has all the contents and add it to a View that's inside your ActivityGroup. LocalActivityManager manages everything for you, like sending onPause and onResume to your inner Activities when you press the home button and such
synic
one more thing: what is this "window" object and how is it implemented? can i just put a `<window>` tag in the layout where i want it to go and then assign it in the code? ps thanks, you're awesome.
mtmurdock
figured it out. You've been a huge help. Thanks
mtmurdock
A: 

Hi,

I have tabhost with multiple activities, in first activity i have button when i click this button, i need to display second activity without loosing my tabhost and header, once i get my second activity in this also i have 2 button when i click first button, it should go back to my first activity and when i click second button it should go back to third activity. i did coding using the following

Intent activityCurrentSummaryIntent = new Intent(v.getContext(), currentsummary.class); activityCurrentSummaryIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

View view = ArchiveGroup.group.getLocalActivityManager().startActivity("ShowPodcasts", activityCurrentSummaryIntent).getDecorView();

ArchiveGroup.group.setContentView(view);

or

replaceContentView("currentsummary", activityCurrentSummaryIntent);

public void replaceContentView(String id, Intent newIntent) { LocalActivityManager mLocalActivityManager = getLocalActivityManager(); View view = mLocalActivityManager.startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView(); this.setContentView(view); }

when i click button i am getting stopped unexpectedly error. Could you please suggest solution for this as early as possible,

Thanking you in advance

WIth Regards, Roy

please send me email with solution/source code to [email protected]

jithendra
This answer has nothing to do with my question, and the question was answered months ago.
mtmurdock