Can I use Activity Group to show two activities at the same time in Android?

2k views Asked by At

I'd like to show two different activities at the same time on the screen. I was under the impression that one may achieve it using ActivityGroup. Is that so?

UPDATE

I tried it this way:

layout = (ListView) findViewById(R.id.wrapper_layout);

LocalActivityManager mgr = getLocalActivityManager();

Intent intent = new Intent(this, BenchMarker.class);

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

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

But got a NullPointerException thrown by ActivityThread.performLaunchActivity()

1

There are 1 answers

4
Albus Dumbledore On BEST ANSWER

Yes, I can. I'll write the solution later these days.

UPDATE

Here's how to do it.

First, you'd need a suitable layout, say res/layout/multiview.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/multiview_layout">
    <LinearLayout android:id="@+id/my_view_1"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_weight="1">
    </LinearLayout>
    <LinearLayout android:layout_height="fill_parent"
        android:layout_width="fill_parent" android:layout_weight="1"
        android:id="@+id/my_view_2">
    </LinearLayout>
</LinearLayout>

And in your main activity that will play the role of a launcher:

public class MyMultiViewActivity extends ActivityGroup {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.multiview);
        layout = (LinearLayout) findViewById(R.id.multiview_layout);
        layout_s1 = (LinearLayout) findViewById(R.id.my_view_1);
        layout_s2 = (LinearLayout) findViewById(R.id.my_view_2);

        LocalActivityManager mgr = getLocalActivityManager();

        layout_s1.addView((mgr.startActivity("MyOtherActivityInstance1", new Intent(this, MyOtherActivity.class))).getDecorView());
        layout_s2.addView((mgr.startActivity("MyOtherActivityInstance2", new Intent(this, MyOtherActivity.class))).getDecorView());
    }

    LinearLayout layout;
    LinearLayout layout_s1;
    LinearLayout layout_s2;
}