title: Restrict an activities SetContentView to display inside an existing container
body: <p>I have a complex imported package that creates an activity and then uses SetContentView on an R.layout file. This layout essentially inflates and covers the screen, but I would like it to only &quot;inflate&quot; inside an existing view that is attached to MainActivity.</p>
  <p>The activity class looks something like this</p>
  <pre><code>public class ExampleActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
      setTheme(R.style.Theme_AppCompat_NoActionBar);
      super.onCreate(savedInstanceState);
      setContentView(R.layout.example_layout);
    }
  }
  </code></pre>
  <p>And I would call it from something like a clickListener with a function like this (where activity is MainActivity)</p>
  <pre><code>public static void startNewActivity(Activity activity) {
      Intent navigationActivity = new Intent(activity, ExampleActivity.class);
      activity.startActivity(navigationActivity);
    }
  </code></pre>
  <p>activity_main.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:mapbox=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:background=&quot;#AFAFB1&quot;
      tools:context=&quot;.MainActivity&quot;&gt;
  
  
      &lt;LinearLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          android:orientation=&quot;vertical&quot;
          android:id=&quot;viewToFill&quot;&gt;
      &lt;/LinearLayout&gt;
       
  
  &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  </code></pre>
  <p>So the question I'm asking is would it be possible to set an activity up so that when SetContentView is called a predefined view (attached to MainActivity) is filled instead of the entire screen. In simple terms, have SetContentView put R.layout.example_layout into the linearlayout viewToFill in activity_main.xml.</p>
  <p>Any help would be appreciated, I have ideas of working around it, it's just that this solution is by far the least involved if it's possible, but I'm very aware it may not be</p>
  <p>edit: made it clearer that the target layout is attached to a different activity than the new layout created by SetContentView</p>