Load a foreign activity into own view?
<p>I'm trying to load the main activity of another app into my own view hierarchy, similar to what can be done with "Fragments".</p>

<p>I've tried:</p>

<pre><code>Context foreignContext = createPackageContext("com.android.calculator2", Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE);
Class&lt;?&gt; foreignClass = foreignContext.getClassLoader().loadClass("com.android.calculator2.Calculator");
Intent intent = new Intent(this, foreignClass);

View view = getLocalActivityManager()
          .startActivity("ReferenceName", intent
          .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
          .getDecorView();
          this.setContentView(view);
</code></pre>

<p>This fails with a <code>ClassNotFoundException</code> as it tries to find <code>com.my.app/com.android.calculator2.Calculator</code> (I assume the <code>Local</code> in <code>getLocalActivityManager</code> adds the prefix?)</p>

<p>Is there any way to achieve this? I don't need to interact with the foreign activity or its code, just display it within my own activity, so simply launching it with an intent wouldn't work. I thought this wasn't possible due to security considerations, but if I can (theoretically) access the foreign app's code, it should be possible to somehow run its <code>onCreate</code> method? </p>

<p>Thanks!</p>
